blob: 50346100b664a6a7f07b65330c264641727f4366 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
;;; armstrong-numbers.el --- armstrong-numbers Exercise (exercism)
;;; 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
|