Sha256: 0629e5a77fd095fb9ed86c5f2d2aa3f504e0bd664e6ac14a1ae0fa1d7778e3ec
Contents?: true
Size: 568 Bytes
Versions: 395
Compression:
Stored size: 568 Bytes
Contents
;;; perfect-numbers.el --- perfect-numbers Exercise (exercism) ;;; Commentary: ;;; Code: (require 'cl) (defun divisors (n) (cl-loop for i from 1 to (truncate (sqrt n)) if (= (% n i) 0) collect i and if (not (= i (/ n i))) collect (/ n i))) (defun sum-divisors (n) ;; Remove n from the list and add'em up. (apply '+ (cdr (sort (divisors n) '>)))) (defun perfect-numbers (n) (cl-loop for i from 2 to n by 2 when (= i (sum-divisors i)) collect i)) (provide 'perfect-numbers) ;;; perfect-numbers.el ends here
Version data entries
395 entries across 395 versions & 1 rubygems