Skip to content
This repository was archived by the owner on Feb 11, 2018. It is now read-only.

Commit

Permalink
Add hamming exercise
Browse files Browse the repository at this point in the history
  • Loading branch information
mbertheau committed May 1, 2015
1 parent 9f10832 commit 9a49530
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"repository": "https://github.com/exercism/xracket",
"active": false,
"problems": [
"bob"
"bob",
"hamming"
]
}
11 changes: 11 additions & 0 deletions hamming/example.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#lang racket

(define (hamming-distance dna1 dna2)
(if (= (string-length dna1) (string-length dna2))
(length (for/list ([c1 (in-string dna1)]
[c2 (in-string dna2)]
#:unless (eq? c1 c2))
c1))
#f))

(provide hamming-distance)
33 changes: 33 additions & 0 deletions hamming/hamming-test.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#lang racket

(require rackunit
"example.rkt")

(check-equal? 0 (hamming-distance "A" "A")
"identical strands")
(check-equal? 0 (hamming-distance "GGACTGA" "GGACTGA")
"long identical strands")
(check-equal? 1 (hamming-distance "A" "G")
"complete distance in single nucleotide strands")
(check-equal? 2 (hamming-distance "AG" "CT")
"complete distance in small strands")
(check-equal? 1 (hamming-distance "AT" "CT")
"small distance in small strands")
(check-equal? 1 (hamming-distance "GGACG" "GGTCG")
"small distance")
(check-equal? 2 (hamming-distance "ACCAGGG" "ACTATGG")
"small distance in long strands")
(check-equal? 1 (hamming-distance "AGA" "AGG")
"non-unique character in first strand")
(check-equal? 1 (hamming-distance "AGG" "AGA")
"non-unique character in second strand")
(check-equal? 4 (hamming-distance "GATACA" "GCATAA")
"large distance")
(check-equal? 9 (hamming-distance "GGACGGATTCTG" "AGGACGGATTCT")
"large distance in off-by-one strand")
(check-equal? 0 (hamming-distance "" "")
"empty strands")
(check-equal? #f (hamming-distance "AATG" "AAA")
"disallow first strand longer")
(check-equal? #f (hamming-distance "ATA" "AGTG")
"disallow second string longer")

0 comments on commit 9a49530

Please sign in to comment.