Skip to content

Instantly share code, notes, and snippets.

@julianjelfs
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save julianjelfs/81e2dd976625f31574ff to your computer and use it in GitHub Desktop.
Save julianjelfs/81e2dd976625f31574ff to your computer and use it in GitHub Desktop.
(defn relative-to [prev next]
(if prev
(let [[pr pc] prev
[nr nc] next]
[(+ pr nr) (+ pc nc)])
next))
(defn tetrominos
"all tetrominos start at [0 0]"
([] (tetrominos [[0 0]]))
([so-far]
(if (= 4 (count so-far))
so-far
(mapcat identity (for [c [[-1 0] [1 0] [0 -1] [0 1]]]
(tetrominos (conj so-far (relative-to (last so-far) c))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment