This repository was archived by the owner on Feb 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"repository": "https://github.com/exercism/xracket", | ||
"active": false, | ||
"problems": [ | ||
"bob" | ||
"bob", | ||
"hamming" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |