summary refs log tree commit diff stats
path: root/raku/hamming/Hamming.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'raku/hamming/Hamming.rakumod')
-rw-r--r--raku/hamming/Hamming.rakumod12
1 files changed, 12 insertions, 0 deletions
diff --git a/raku/hamming/Hamming.rakumod b/raku/hamming/Hamming.rakumod
new file mode 100644
index 0000000..075b07c
--- /dev/null
+++ b/raku/hamming/Hamming.rakumod
@@ -0,0 +1,12 @@
+unit module Hamming;
+
+subset DNA of Str where * !~~ /<-[ACGT]>/;
+sub hamming-distance(
+    DNA $strand1, DNA $strand2 where $strand1.chars == $strand2.chars --> Int
+) is export {
+    my Int $dist = 0;
+    for ^$strand1.chars -> $idx {
+        $dist++ unless $strand1.comb[$idx] eq $strand2.comb[$idx];
+    }
+    return $dist;
+}