[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
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
(with-temp-buffer
(insert-file-contents "input")
@ -23,15 +23,18 @@ This is for part 1; only two repetitions
(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))))
(mult (expt 10 (floor (/ num-digits 2)))))
(= (mod num mult) (/ num mult))))
(-sum
(apply #'append
(--map (-filter #'invalid-id-p it) (-map #'create-range data))))
(--mapcat (-filter #'invalid-id-p it)
(-map #'create-range data)))
#+end_src
#+RESULTS:
: 1227775554
rsjjdj
: 24157613387
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)))))
(-sum
(apply #'append
(--map (-filter #'invalid-id-p it) (-map #'create-range data))))
(--mapcat (-filter #'invalid-id-p it)
(-map #'create-range data)))
#+end_src
#+RESULTS:
: 33832678380
: 4174379265

Loading…
Cancel
Save