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

Version Path
trackler-2.2.1.180 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.179 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.178 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.177 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.176 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.175 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.174 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.173 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.172 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.171 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.170 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.169 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.167 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.166 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.165 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.164 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.163 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.162 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.161 tracks/elisp/exercises/perfect-numbers/example.el
trackler-2.2.1.160 tracks/elisp/exercises/perfect-numbers/example.el