Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn move-hex
[point direction]
(case direction
:ne [(inc (point 0)) (dec (point 1))]
:se [(inc (point 0)) (point 1)]
:s [(point 0) (inc (point 1))]
:sw [(dec (point 0)) (inc (point 1))]
:nw [(dec (point 0)) (point 1)]
:n [(point 0) (dec (point 1))]))
(defn traverse-grid-from-origin
(loop [point [0 0]
max-distance 0
directions directions]
(empty? directions) (max-distance point)
:else (let [new-point (move-hex point (first directions))
current-distance (max-distance new-point)]
(recur new-point
(if (>= current-distance max-distance)
(rest directions))))))
(defn max-distance
(Math/max (Math/abs (point 0)) (Math/abs (point 1))))
;; this fails when running, but stepping through it works.
(traverse-grid-from-origin [:s])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment