Skip to content

Instantly share code, notes, and snippets.

@sbenhaim
Last active December 16, 2015 03:01
Show Gist options
  • Save sbenhaim/7f251e6062c47f79f424 to your computer and use it in GitHub Desktop.
Save sbenhaim/7f251e6062c47f79f424 to your computer and use it in GitHub Desktop.
Advent of Code: 3
(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