hamming.scm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
(define-module (hamming)
  #:export (hamming-distance))

(define (compare-list sq1-list sq2-list)
  (if (not (null? sq1-list))
    (if (not (eq? (car sq1-list) (car sq2-list)))
      (+ 1 (compare-list (cdr sq1-list) (cdr sq2-list)))
      (+ 0 (compare-list (cdr sq1-list) (cdr sq2-list)))
      )
    0
    )
  )
   
(define (hamming-distance sq1 sq2)
  (define sq1-list (string->list sq1))
  (define sq2-list (string->list sq2))
  (if (eq? (length sq1-list) (length sq2-list))
    (compare-list sq1-list sq2-list)
    (throw 'lists-inequal)
    )
  )

Comments


You're not logged in right now. Please login via GitHub to comment