From 7eb1e664c8d6b0abdc86753fca6f5df280aa3428 Mon Sep 17 00:00:00 2001 From: Kjetil Orbekk Date: Mon, 22 Nov 2021 07:38:52 -0500 Subject: hamming solution --- exercism/emacs-lisp/hamming/hamming.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'exercism/emacs-lisp/hamming') 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 -- cgit v1.2.3