Last active
March 13, 2018 08:12
-
-
Save Ssstlis/e519db2c0307ddc5f74813eb56a873d4 to your computer and use it in GitHub Desktop.
Aristov test gist 03.13.2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Text; | |
| using static TestApp.Program.DnaPath; | |
| namespace TestApp | |
| { | |
| class Program | |
| { | |
| internal enum DnaPath | |
| { | |
| A, T, C, G | |
| } | |
| static string DnaToString(DnaPath[] src) | |
| { | |
| if (src == null || src.Length == 0) | |
| throw new Exception(); | |
| StringBuilder builder = new StringBuilder(); | |
| foreach (var path in src) | |
| switch (path) | |
| { | |
| case A: | |
| builder.Append('A'); break; | |
| case T: | |
| builder.Append('T'); break; | |
| case C: | |
| builder.Append('C'); break; | |
| case G: | |
| builder.Append('G'); break; | |
| } | |
| return builder.ToString(); | |
| } | |
| static DnaPath[] Compliment(DnaPath[] src) | |
| { | |
| if (src == null || src.Length == 0) | |
| throw new Exception(); | |
| DnaPath[] temp = new DnaPath[src.Length]; | |
| for (int i = 0, stop = src.Length; i < stop; i++) | |
| switch (src[i]) | |
| { | |
| case A: | |
| temp[i] = T; break; | |
| case T: | |
| temp[i] = A; break; | |
| case C: | |
| temp[i] = G; break; | |
| case G: | |
| temp[i] = C; break; | |
| } | |
| return temp; | |
| } | |
| static int Chartohex(char src) | |
| { | |
| switch (src) | |
| { | |
| case 'a': return 0xa; | |
| case 'A': return 0xa; | |
| case 'b': return 0xb; | |
| case 'B': return 0xb; | |
| case 'c': return 0xc; | |
| case 'C': return 0xc; | |
| case 'd': return 0xd; | |
| case 'D': return 0xd; | |
| case 'e': return 0xe; | |
| case 'E': return 0xe; | |
| case 'f': return 0xf; | |
| case 'F': return 0xf; | |
| default: throw new Exception(); | |
| } | |
| } | |
| static int Fish(string src) | |
| { | |
| if (string.IsNullOrEmpty(src)) | |
| throw new Exception(); | |
| int temp = 0; | |
| foreach(char item in src) | |
| try | |
| { | |
| temp ^= Chartohex(item); | |
| } | |
| catch | |
| { | |
| // ignored | |
| } | |
| return temp; | |
| } | |
| static void Main(string[] args) | |
| { | |
| Console.WriteLine(DnaToString(Compliment(new[] { T, A, C, G, T, A, G, G, C, T, A }))); | |
| Console.WriteLine(DnaToString(Compliment(new[] { G, A, C, A, C, A, C, G, A, T, C }))); | |
| Console.WriteLine(Fish("asdoiguvaoysvvBPSDPVIOVASYUVEPSFNAjhvaevwuhzblsdvahsvdo")); | |
| Console.WriteLine(Fish("hasceccarcyeacsyradtxcyrcetacyescdtracsdutarsduatyc")); | |
| Console.ReadKey(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment