diff options
Diffstat (limited to 'exercism')
-rw-r--r-- | exercism/emacs-lisp/hamming/hamming.el | 14 | ||||
-rw-r--r-- | exercism/emacs-lisp/run-exercises.el | 4 |
2 files changed, 18 insertions, 0 deletions
diff --git a/exercism/emacs-lisp/hamming/hamming.el b/exercism/emacs-lisp/hamming/hamming.el index 1ef5eeb..468ad63 100644 --- a/exercism/emacs-lisp/hamming/hamming.el +++ b/exercism/emacs-lisp/hamming/hamming.el @@ -4,6 +4,20 @@ ;;; Code: +(require 'cl-seq) +(require 'cl-lib) + +(defun kj/sum (lst) + (cl-reduce #'+ lst :initial-value 0)) + +(defun hamming-distance (l1 l2) + (when (not (eql (length l1) (length l2))) + (error 'lengths-differ)) + (let ((fn (lambda (x y) + (if (equal x y) + 0 + 1)))) + (kj/sum (cl-mapcar fn l1 l2)))) (provide 'hamming) ;;; hamming.el ends here diff --git a/exercism/emacs-lisp/run-exercises.el b/exercism/emacs-lisp/run-exercises.el index 44831a6..39372e3 100644 --- a/exercism/emacs-lisp/run-exercises.el +++ b/exercism/emacs-lisp/run-exercises.el @@ -51,4 +51,8 @@ (kj-display "Roman numerals" (to-roman 1990)) +(load-file "hamming/hamming.el") +(kj-display "Hamming distance" + (hamming-distance "GGACGGATTCTG" "AGGACGGATTCT")) + (provide 'hello) |