Last active
February 29, 2016 15:13
-
-
Save def-/19feec0a66d350f9fcf9 to your computer and use it in GitHub Desktop.
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
| import algorithm | |
| # Complementing a strand of DNA | |
| # I want to reverse the string "s" and then replace | |
| # all A's with T's | |
| # all T's with A's | |
| # all C's with G's | |
| # all G's with C's | |
| # define my string variable | |
| var s: string = "AAACCCGGT" | |
| # reverse my string variable | |
| reverse(s) | |
| proc replaceInplace(s: var string) = | |
| for c in s.mitems: | |
| case c | |
| of 'A': c = 'T' | |
| of 'C': c = 'G' | |
| of 'G': c = 'C' | |
| of 'T': c = 'A' | |
| else: discard | |
| proc replaceInplace2(s: var string) = | |
| for i, c in s: | |
| case c | |
| of 'A': s[i] = 'T' | |
| of 'C': s[i] = 'G' | |
| of 'G': s[i] = 'C' | |
| of 'T': s[i] = 'A' | |
| else: discard | |
| # replace all my letters | |
| replaceInplace(s) | |
| # print out result | |
| echo s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment