From 275fb6919260a545ca46181e297cdfe4a1880865 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Fri, 8 Mar 2013 03:04:42 -0600 Subject: couple more rust solutions --- REVC.rs | 26 ++++++++++++++++++++++++++ RNA.rs | 12 ++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 REVC.rs create mode 100644 RNA.rs diff --git a/REVC.rs b/REVC.rs new file mode 100644 index 0000000..3c9e9e7 --- /dev/null +++ b/REVC.rs @@ -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)); +} diff --git a/RNA.rs b/RNA.rs new file mode 100644 index 0000000..30091fe --- /dev/null +++ b/RNA.rs @@ -0,0 +1,12 @@ +use io::{stdin,stdout,ReaderUtil,WriterUtil}; + +fn main() { + let stdout = stdout(); + for stdin().each_char() |ch| { + match ch { + 'T' => { stdout.write_char('U') } + '\n' => { stdout.write_char(ch); return } + _ => { stdout.write_char(ch) } + } + } +} -- cgit v1.2.3-54-g00ecf