|
|
|
|
@ -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,7 +96,7 @@ Now define the instructions and run, for part 1 |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
: 1,5,0,3,7,3,0,3,1 |
|
|
|
|
: 3 |
|
|
|
|
|
|
|
|
|
now for part 2 we create the initial value 3 bits at a time |
|
|
|
|
#+begin_src emacs-lisp |
|
|
|
|
@ -100,34 +105,36 @@ now for part 2 we create the initial value 3 bits at a time |
|
|
|
|
|
|
|
|
|
(defun setup-registers (data) |
|
|
|
|
(setq A (prep-reg data) |
|
|
|
|
B 0 |
|
|
|
|
C 0)) |
|
|
|
|
B 0 |
|
|
|
|
C 0)) |
|
|
|
|
|
|
|
|
|
(defun exec (pr data) |
|
|
|
|
(let ((so nil) |
|
|
|
|
(ip 0) |
|
|
|
|
(stack-trace nil)) |
|
|
|
|
(ip 0) |
|
|
|
|
(stack-trace nil)) |
|
|
|
|
|
|
|
|
|
(setup-registers data) |
|
|
|
|
(setup-registers data) |
|
|
|
|
|
|
|
|
|
(while (nth ip pr) |
|
|
|
|
(eval (nth ip pr)) |
|
|
|
|
(setq ip (1+ ip))) |
|
|
|
|
(while (nth ip pr) |
|
|
|
|
(eval (nth ip pr)) |
|
|
|
|
(setq ip (1+ ip))) |
|
|
|
|
|
|
|
|
|
(reverse so))) |
|
|
|
|
(reverse so))) |
|
|
|
|
|
|
|
|
|
(setq data (-last-item (-iterate #'grow-data '(nil) 4)) |
|
|
|
|
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))) |
|
|
|
|
(setq data (-last-item (-iterate #'grow-data '(nil) 4)) |
|
|
|
|
target (-flatten program)) |
|
|
|
|
|
|
|
|
|
(good-data data) |
|
|
|
|
(exec proggo '(1 2)) |
|
|
|
|
target |
|
|
|
|
(defun good-data (data) |
|
|
|
|
(let ((n (- (length (car data)) 2))) |
|
|
|
|
(--filter (equal (-take n (exec proggo it)) (-take n target)) (grow-data data)))) |
|
|
|
|
(setq aaaa (-last-item (-iterate #'good-data data 15))) |
|
|
|
|
(-min (-map 'prep-reg (--filter (equal (exec proggo it) target) aaaa))) |
|
|
|
|
#+end_src |
|
|
|
|
|
|
|
|
|
#+RESULTS: |
|
|
|
|
: 105981155568026 |
|
|
|
|
|