summaryrefslogtreecommitdiffstats
path: root/rosalind/str.rs
blob: 783705517e430db01225b36ed8e8189db09d5a46 (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
}