hamming.el (754B)

1 ;;; hamming.el --- Hamming (exercism) 2 3 ;;; Commentary: 4 5 ;;; Code: 6 7 (provide 'hamming) 8 9 (defun count-different-chars(s1 s2) 10 "Count the number of different characters between two strings, S1 and S2, which must be of equal length." 11 (let ((count 0) (i 0)) 12 (while (< i (length s1)) 13 (if (not (char-equal (aref s1 i) (aref s2 i))) 14 (setq count (+ count 1))) 15 (setq i (+ i 1))) 16 count)) 17 18 (defun hamming-distance(s1 s2) 19 "Determine the Hamming distance of two strands of DNA. 20 Expects the strands as two strings, S1 and S2, 21 which must be of equal length." 22 (cond ((string= s1 s2) 0) 23 ((eq (length s1) (length s2)) (count-different-chars s1 s2)) 24 (error "Strands must be of equal length"))) 25 26 ;;; hamming.el ends here