Skip to content

Instantly share code, notes, and snippets.

@pavloo
Created December 11, 2017 21:12
Show Gist options
  • Save pavloo/d3838a4cf9cd0ee65173516efb26ce92 to your computer and use it in GitHub Desktop.
Save pavloo/d3838a4cf9cd0ee65173516efb26ce92 to your computer and use it in GitHub Desktop.
(defun read-words-from-file (file-path)
(with-temp-buffer
(insert-file-contents file-path)
(mapcar 'string-to-number (split-string (buffer-string) "\n" t))
)
)
(read-words-from-file "./input.txt")
(defun escape-maze (list)
"Solution for Day #5 Part 2 http://adventofcode.com/2017/day/5"
(let ((steps 0) (i 0) (val) d)
(while (and (>= i 0) (< i (length list)))
(setq val (nth i list))
(if (>= val 3) (setq d -1) (setq d 1))
(setcar (nthcdr i list) (+ val d))
(setq steps (1+ steps))
(setq i (+ i val))
)
steps
)
)
(escape-maze '(0 3 0 1 -3)) ;; 10
(escape-maze '(3 1 2 4)) ;; 2
(escape-maze (read-words-from-file "./input.txt"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment