main
Jacopo De Simoi 11 months ago
parent 6f568723ea
commit 0a78796a56
  1. 52
      p17/p17.org

@ -9,7 +9,7 @@ Load program
(replace-regexp a b))
(with-temp-buffer
(insert-file-contents "input-test")
(insert-file-contents "input")
(replace-regexp-from-top "Register \\(.\\): \\(.*\\)$" "(setq \\1 \\2)")
(replace-regexp-from-top "\\(.\\),\\(.\\)" "(\\1 \\2)")
@ -33,8 +33,13 @@ Convert the opcodes into instructions
#+end_src
#+RESULTS:
| adv | 1 |
| out | 4 |
| bst | 4 |
| bxl | 5 |
| cdv | 5 |
| bxl | 6 |
| adv | 3 |
| bxc | 1 |
| out | 5 |
| jnz | 0 |
@ -91,4 +96,43 @@ Now define the instructions and run, for part 1
#+end_src
#+RESULTS:
: 4,6,3,5,6,3,5,2,1,0
: 1,5,0,3,7,3,0,3,1
now for part 2 we create the initial value 3 bits at a time
#+begin_src emacs-lisp
(defun prep-reg (data)
(apply #'+ (--map-indexed (ash it (* 3 it-index)) data)) )
(defun setup-registers (data)
(setq A (prep-reg data)
B 0
C 0))
(defun exec (pr data)
(let ((so nil)
(ip 0)
(stack-trace nil))
(setup-registers data)
(while (nth ip pr)
(eval (nth ip pr))
(setq ip (1+ ip)))
(reverse so)))
(setq data (list nil)
target (-flatten program))
(defun grow-data (data)
(--mapcat (-map (lambda (i) (append it (list i))) (-iota 8)) data)
)
(defun good-data (data)
(--filter (-is-prefix-p (exec proggo it) target) ) (grow-data data))
(-iterate #'good-data data (length target))
(good-data '((1)))
(exec proggo '(1 2))
target
#+end_src

Loading…
Cancel
Save