Last active
December 4, 2015 16:16
-
-
Save underhilllabs/7c4839b3ceddecc32df9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(def route (slurp "./houses.txt")) | |
(def visits (set [])) | |
;; (conj " | |
;; (def current {:x 0, :y 0}) | |
;; Add 1 to x | |
;; (def current (assoc current :x (+ 1 (get current :x)))) | |
(defn inc-x [] | |
(def current (assoc current :x (inc (get current :x))))) | |
(defn inc-y [] | |
(def current (assoc current :y (inc (get current :y))))) | |
(defn dec-x [] | |
(def current (assoc current :x (dec (get current :x))))) | |
(defn dec-y [] | |
(def current (assoc current :y (dec (get current :y))))) | |
(defn move [ch] | |
(case ch | |
\^ (dec-x) | |
\v (inc-x) | |
\< (dec-y) | |
\> (inc-y) | |
"")) | |
(defn show-addr [cur] | |
(keyword (str (get cur :x) "_" (get cur :y)))) | |
(defn update-visits [] | |
(def visits (conj visits (show-addr current)))) | |
(defn move-and-update [ch] | |
(move ch) | |
(update-visits)) | |
(defn run-santa [] | |
(for [x (seq routes)] | |
(move-and-update x) | |
x)) | |
(defn reset-santa [] | |
(def visits (set [])) | |
(def current {:x 0, :y 0})) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment