Skip to content

Instantly share code, notes, and snippets.

@Arnot
Created April 18, 2018 16:04
Show Gist options
  • Save Arnot/e8c39ff906a09e0ce0a86d7b204017f7 to your computer and use it in GitHub Desktop.
Save Arnot/e8c39ff906a09e0ce0a86d7b204017f7 to your computer and use it in GitHub Desktop.
(setf day10-input '(189 1 111 246 254 2 0 120 215 93 255 50 84 15 94 62))
(defun reverse-sublist (list beg end)
(let ((rotated-list (-rotate (- beg) list))
(nend (- end beg)))
(setf (subseq rotated-list 0 nend) (reverse (subseq rotated-list 0 nend)))
(-rotate beg rotated-list)))
(defun make-hash-list (size)
(let ((result '()))
(dotimes (i size)
(push i result))
(nreverse result)))
(defun day10-p1 ()
(let ((hash-list (make-hash-list 256))
(current-pos 0)
(skip-size 0))
(dolist (len day10-input)
(setf hash-list (reverse-sublist hash-list current-pos (+ len current-pos)))
(setf current-pos (mod (+ current-pos len skip-size) 256))
(incf skip-size))
(* (first hash-list) (second hash-list))))
(day10-p1)
;; 38415
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment