summaryrefslogtreecommitdiffstats
path: root/REVC.rs
blob: 3c9e9e796e4577f75577e0bfd557b67f3af5e8b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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));
}