-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added solution for day 21. This only works for my registers so probably won't do for other inputs.
- Loading branch information
Showing
3 changed files
with
28 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
|
||
;;;; day19.lisp | ||
|
||
(in-package :advent-of-code-2018) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
;;;; day21.lisp | ||
|
||
(in-package :advent-of-code-2018) | ||
|
||
;;; works for my input | ||
;;; how to find the correct register? would need more puzzle inputs probably | ||
(defun day21-next (state) | ||
(loop | ||
:while (day19-execute! state) | ||
:until (= 28 (pstate-ip state)) | ||
:finally (return (aref (pstate-registers state) 1)))) | ||
|
||
;;; Part 2 slow | ||
;;; further reassembling the code by hand would probably allow for optimization | ||
(defun day21 () | ||
(let* ((state (day19-initialize-program (day19-parse-input (puzzlefile 21)))) | ||
(first-value (day21-next state))) | ||
(format t "A value of ~a ends the program fastest.~%" first-value) | ||
(loop :with seen := (make-hash-table) | ||
:for prev-value := nil :then next-value | ||
:for next-value := first-value :then (day21-next state) | ||
:until (gethash next-value seen nil) | ||
:do (setf (gethash next-value seen) t) | ||
:finally (format t "A value of ~a ends the program the latest.~%" prev-value)))) |