[p2] cleanup

master
Jacopo De Simoi 6 months ago
parent 551704e191
commit fe16e91bde
  1. 19
      p2/p2.org

@ -1,6 +1,6 @@
#+title: Solution to p2 #+title: Solution to p2
First load the data as a list of cons cells (stsrt . end) First load the data as a list of cons cells (start . end)
#+begin_src emacs-lisp :results none #+begin_src emacs-lisp :results none
(with-temp-buffer (with-temp-buffer
(insert-file-contents "input") (insert-file-contents "input")
@ -23,15 +23,18 @@ This is for part 1; only two repetitions
(defun invalid-id-p (num) (defun invalid-id-p (num)
(let* ((num-digits (1+ (floor (log num 10)))) (let* ((num-digits (1+ (floor (log num 10))))
(factor (expt 10 (floor (/ num-digits 2))))) (mult (expt 10 (floor (/ num-digits 2)))))
(= (mod num factor) (/ num factor)))) (= (mod num mult) (/ num mult))))
(-sum (-sum
(apply #'append (--mapcat (-filter #'invalid-id-p it)
(--map (-filter #'invalid-id-p it) (-map #'create-range data)))) (-map #'create-range data)))
#+end_src #+end_src
#+RESULTS: #+RESULTS:
: 1227775554
rsjjdj
: 24157613387 : 24157613387
This is for part 2: very inefficient, but it works This is for part 2: very inefficient, but it works
@ -51,9 +54,9 @@ This is for part 2: very inefficient, but it works
(-map #'-distinct (--map (chop-num num it) factors))))) (-map #'-distinct (--map (chop-num num it) factors)))))
(-sum (-sum
(apply #'append (--mapcat (-filter #'invalid-id-p it)
(--map (-filter #'invalid-id-p it) (-map #'create-range data)))) (-map #'create-range data)))
#+end_src #+end_src
#+RESULTS: #+RESULTS:
: 33832678380 : 4174379265

Loading…
Cancel
Save