|
|
|
|
@ -3,7 +3,7 @@ |
|
|
|
|
First load the data as a list of cons cells (stsrt . end) |
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
(with-temp-buffer |
|
|
|
|
(insert-file-contents "input-test") |
|
|
|
|
(insert-file-contents "input") |
|
|
|
|
(advent/replace-multiple-regex-buffer |
|
|
|
|
'(("," . "\n") |
|
|
|
|
("-" . " . ") |
|
|
|
|
@ -16,8 +16,20 @@ First load the data as a list of cons cells (stsrt . end) |
|
|
|
|
(eval-buffer)) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+begin_src emacs-lisp :results none |
|
|
|
|
This is for part 1; only two repetitions |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
(defun create-range (rng) |
|
|
|
|
(-iterate #'1+ (car rng) (1+ (- (cdr rng) (car rng))))) |
|
|
|
|
|
|
|
|
|
(defun invalid-id-p (num) |
|
|
|
|
(let* ((num-digits (1+ (floor(log num 10)))) |
|
|
|
|
(factor (expt 10 (floor (/ num-digits 2))))) |
|
|
|
|
(= (mod num factor) (/ num factor)))) |
|
|
|
|
|
|
|
|
|
(-sum |
|
|
|
|
(apply #'append |
|
|
|
|
(--map (-filter #'invalid-id-p it) (-map #'create-range data)))) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
: 24157613387 |
|
|
|
|
|