[p10] start

master
Jacopo De Simoi 3 months ago
parent daeb44775a
commit bed1a4d7d7
  1. 51
      p10/p10.org

@ -0,0 +1,51 @@
#+title: Solution to p10
#+begin_src emacs-lisp :results none
(with-temp-buffer
(insert-file-contents "input-test")
(advent/replace-multiple-regex-buffer
'(("," . " ")
("^" . "(")
("$" . ")")
("\\[" . "\"")
("\\]" . "\"")
("{" . "(")
("}" . ")")
))
(goto-char (point-min))
(insert "(setq data '(")
(goto-char (point-max))
(insert "))")
(eval-buffer))
#+end_src
#+begin_src emacs-lisp
(defun zero-one (n)
(if (eq n ?#) 1 0))
(setq cleanedup-data (--map (cons (-map #'zero-one (advent/split-string-into-char-list (car it))) (cdr it)) data))
#+end_src
#+RESULTS:
| (0 1 1 0) | (3) | (1 3) | (2) | (2 3) | (0 2) | (0 1) | (3 5 4 7) |
| (0 0 0 1 0) | (0 2 3 4) | (2 3) | (0 4) | (0 1 2) | (1 2 3 4) | (7 5 12 7 2) | |
| (0 1 1 1 0 1) | (0 1 2 3 4) | (0 3 4) | (0 1 2 4 5) | (1 2) | (10 11 11 5 10 5) | | |
for part 1 we do not need the last item
#+begin_src emacs-lisp
(setq machines (--map (-drop-last 1 it) cleanedup-data))
(defun init-machine (spec)
(setq machine (-repeat (length (car spec)) 0)))
(defun toggle (n)
(logxor 0 1))
(defun toggle-button (button)
(setq machine (--map-indexed (if (-contains-p button it-index) (logxor it 1) it) machine)))
(init-machine (car machines))
(toggle-button '(1))
#+end_src
Loading…
Cancel
Save