summaryrefslogtreecommitdiffstats
path: root/rosalind/str.rs
blob: 0fac1cd2d6bb75e8c185d6daa21b171b0ff58bfd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use str = core::str;

/* 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
}

pure fn hamming(string1: ~str, string2: ~str) -> int {
    let mut hamming = 0;
    for str::each_chari(string1) |i, ch| {
        if ch != str::char_at(string2, i) {
            hamming += 1;
        }
    }
    hamming
}