diff options
author | Jesse Luehrs <doy@tozt.net> | 2013-03-08 03:04:42 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2013-03-08 03:04:42 -0600 |
commit | 275fb6919260a545ca46181e297cdfe4a1880865 (patch) | |
tree | e2e3fdeb39e5b2a281bf977aafe4653d728783ff /REVC.rs | |
parent | 91aa0faa200421e5a95fc52d20e492288dc94f31 (diff) | |
download | rosalind-275fb6919260a545ca46181e297cdfe4a1880865.tar.gz rosalind-275fb6919260a545ca46181e297cdfe4a1880865.zip |
couple more rust solutions
Diffstat (limited to 'REVC.rs')
-rw-r--r-- | REVC.rs | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -0,0 +1,26 @@ +use io::{stdin,println,ReaderUtil}; + +/* really feels like there should be a more efficient way to do this */ +fn reverse(s: &str) -> ~str { + let mut r = ~""; + str::reserve(&mut r, str::len(s)); + for str::each_char(s) |ch| { + str::unshift_char(&mut r, ch) + } + r +} + +fn complement(ch: char) -> char { + match ch { + 'A' => 'T', + 'C' => 'G', + 'G' => 'C', + 'T' => 'A', + _ => fail ~"Unknown character found", + } +} + +fn main() { + let dna = stdin().read_line(); + println(str::map(reverse(dna), complement)); +} |