Last active
December 16, 2015 03:01
-
-
Save sbenhaim/7f251e6062c47f79f424 to your computer and use it in GitHub Desktop.
Advent of Code: 3
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
(ns advent.a3 | |
(:require [clojure.string :as str])) | |
(let [a3 (str//trim (slurp "a3.txt"))] | |
(count | |
(loop [cs (seq a3) p [0 0] ps #{[0 0]}] | |
(if-not (seq cs) ps | |
(let [c (first cs) | |
[x y] p | |
next (condp = c | |
\> [(inc x) y] | |
\< [(dec x) y] | |
\^ [x (inc y)] | |
\v [x (dec y)])] | |
(recur (rest cs) next (conj ps next))))))) | |
(let [a3 (str/trim (slurp "a3.txt"))] | |
(count | |
(loop [cs (seq a3) p [[0 0] [0 0]] ps #{[0 0]}] | |
(if-not (seq cs) ps | |
(let [c (first cs) | |
[mover waiter] p | |
[x y] mover | |
next (condp = c | |
\> [(inc x) y] | |
\< [(dec x) y] | |
\^ [x (inc y)] | |
\v [x (dec y)])] | |
(recur (rest cs) [waiter next] (conj ps next))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment