diff options
Diffstat (limited to 'exercism/emacs-lisp')
-rw-r--r-- | exercism/emacs-lisp/armstrong-numbers/armstrong-numbers.el | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/exercism/emacs-lisp/armstrong-numbers/armstrong-numbers.el b/exercism/emacs-lisp/armstrong-numbers/armstrong-numbers.el index d41293c..5034610 100644 --- a/exercism/emacs-lisp/armstrong-numbers/armstrong-numbers.el +++ b/exercism/emacs-lisp/armstrong-numbers/armstrong-numbers.el @@ -3,6 +3,21 @@ ;;; Commentary: ;;; Code: +(require 'calc) +(require 'seq) + +(defun kj/digits (n) + (let ((result nil)) + (while (> n 0) + (push (% n 10) result) + (setq n (/ n 10))) + result)) + +(defun armstrong-p (n) + (let* ((digits (kj/digits n)) + (ndigits (seq-length digits)) + (fn (lambda (n) (math-pow n ndigits)))) + (eql n (apply '+ (mapcar fn digits))))) (provide 'armstrong-numbers) ;;; armstrong-numbers.el ends here |