Skip to content

Instantly share code, notes, and snippets.

@def-
Last active February 29, 2016 15:13
Show Gist options
  • Select an option

  • Save def-/19feec0a66d350f9fcf9 to your computer and use it in GitHub Desktop.

Select an option

Save def-/19feec0a66d350f9fcf9 to your computer and use it in GitHub Desktop.
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