Created
December 5, 2017 15:53
-
-
Save rhinoman/31a247907d52316f245837861cf7b04b to your computer and use it in GitHub Desktop.
Advent of Code 2017 Day 5 solution
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
(defun solution-p1 (in) | |
(let* ((idx 0) | |
(xs (copy-sequence in)) | |
(num-steps 0) | |
(len (length xs))) | |
(while (and (> idx -1) (< idx len)) | |
(let ((cur (aref xs idx))) | |
(aset xs idx (+ cur 1)) | |
(setq idx (+ idx cur)) | |
(setq num-steps (+ num-steps 1))) | |
) | |
num-steps) | |
) | |
(defun solution-p2 (in) | |
(let* ((idx 0) | |
(xs (copy-sequence in)) | |
(num-steps 0) | |
(len (length xs))) | |
(while (and (> idx -1) (< idx len)) | |
(let ((cur (aref xs idx))) | |
(if (>= cur 3) | |
(aset xs idx (- cur 1)) | |
(aset xs idx (+ cur 1))) | |
(setq idx (+ idx cur)) | |
(setq num-steps (+ num-steps 1))) | |
) | |
num-steps) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment