p24 musings

main
Jacopo De Simoi 6 months ago
parent 77837dc8f8
commit 21f968db8d
  1. 32
      p24/p24.org

@ -1,10 +1,12 @@
#+title: Solution to p24 #+title: Solution to p24
#+begin_src emacs-lisp :results none #+begin_src emacs-lisp :results none
(require 'dash) (require 'dash)
(org-babel-lob-ingest "../lib/advent-lib.org")
(setq zzz (--map (intern (format "z%02d" it)) (-iterate #'1+ 0 100))) (setq zzz (--map (intern (format "z%02d" it)) (-iterate #'1+ 0 100)))
(-each zzz #'unintern) (-each zzz #'unintern)
(with-temp-buffer (with-temp-buffer
(insert-file-contents "input") (insert-file-contents "input-test")
(goto-char (point-min)) (goto-char (point-min))
(advent/replace-multiple-regex-buffer (advent/replace-multiple-regex-buffer
'(("^\\(.*\\):\\(.*\\)$" . "\\1 \\2") '(("^\\(.*\\):\\(.*\\)$" . "\\1 \\2")
@ -32,19 +34,37 @@
(defun AND (a b) (defun AND (a b)
(when (good-vars a b) (when (good-vars a b)
(logand (eval a) (eval b)))) (logand (eval a) (eval b))))
#+end_src #+end_src
#+begin_src emacs-lisp #+begin_src emacs-lisp
(step) (step)
(setq used-zzz (-filter #'boundp (--map (intern (format "z%02d" it)) (-iterate #'1+ 0 100)))) (setq
used-xxx (-filter #'boundp (--map (intern (format "x%02d" it)) (-iterate #'1+ 0 100)))
used-yyy (-filter #'boundp (--map (intern (format "y%02d" it)) (-iterate #'1+ 0 100)))
used-zzz (-filter #'boundp (--map (intern (format "z%02d" it)) (-iterate #'1+ 0 100))))
(defun run ()
(while (not (-every #'eval used-zzz)) (while (not (-every #'eval used-zzz))
(step)) (step)))
(defun reset-var (li)
(--each li (setq it nil)))
(apply #'+ (--map-indexed (* (eval it) (ash 1 it-index)) used-zzz)) (defun set-var (li a)
(--each-indexed li (setq it (logand 1 (ash a (* -1 it-index)))))
)
(defun var-value (li)
(apply #'+ (--map-indexed (* (eval it) (ash 1 it-index)) li)))
(reset-var used-zzz)
(set-var used-xxx 0)
(set-var used-yyy 0)
(run)
(var-value used-zzz)
#+end_src #+end_src
#+RESULTS: #+RESULTS:
: 36035961805936 : 2024
(length used-zzz)

Loading…
Cancel
Save