|
|
|
@ -33,3 +33,27 @@ This is for part 1; only two repetitions |
|
|
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
#+RESULTS: |
|
|
|
: 24157613387 |
|
|
|
: 24157613387 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This is for part 2: very inefficient, but it works |
|
|
|
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
|
|
|
(defun factors (num) |
|
|
|
|
|
|
|
(let ((candidates (-iterate #'1+ 1 num))) |
|
|
|
|
|
|
|
(--filter (= num (* it (floor (/ num it)))) candidates))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun chop-num (num len) |
|
|
|
|
|
|
|
(let ((mult (expt 10 len))) |
|
|
|
|
|
|
|
(--unfold (when (> it 0) (cons (mod it mult) (floor (/ it mult)))) num))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun invalid-id-p (num) |
|
|
|
|
|
|
|
(let* ((num-digits (1+ (floor(log num 10)))) |
|
|
|
|
|
|
|
(factors (-drop-last 1 (factors num-digits)))) |
|
|
|
|
|
|
|
(--any (= 1 (length it)) |
|
|
|
|
|
|
|
(-map #'-distinct (--map (chop-num num it) factors))))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(-sum |
|
|
|
|
|
|
|
(apply #'append |
|
|
|
|
|
|
|
(--map (-filter #'invalid-id-p it) (-map #'create-range data)))) |
|
|
|
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
|
|
|
: 33832678380 |
|
|
|
|