summaryrefslogtreecommitdiffstats
path: root/rosalind/str.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2013-03-08 20:14:51 -0600
committerJesse Luehrs <doy@tozt.net>2013-03-08 20:14:51 -0600
commitae98925062d5a392a73df4a1456df3a4a3be9b18 (patch)
tree3b89c49d97b9c38551578bf57619a9649dd0b4fb /rosalind/str.rs
parentb331d192d8da5b7397240d7eced71cbf0ab8cc55 (diff)
downloadrosalind-ae98925062d5a392a73df4a1456df3a4a3be9b18.tar.gz
rosalind-ae98925062d5a392a73df4a1456df3a4a3be9b18.zip
factor common behavior out into a library
Diffstat (limited to 'rosalind/str.rs')
-rw-r--r--rosalind/str.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/rosalind/str.rs b/rosalind/str.rs
new file mode 100644
index 0000000..0fac1cd
--- /dev/null
+++ b/rosalind/str.rs
@@ -0,0 +1,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
+}