Skip to content

Instantly share code, notes, and snippets.

@craftybones
Created February 28, 2019 18:53
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 craftybones/42f180cf753db07b6694de87f4182ece to your computer and use it in GitHub Desktop.
Save craftybones/42f180cf753db07b6694de87f4182ece to your computer and use it in GitHub Desktop.
(def remove-zeroes (partial remove zero?))
(def partition-number-sequences (partial partition-by identity))
(def pair-up (partial partition-all 2))
(def pair-partitions (partial mapcat pair-up))
(def sum-of (partial apply +))
(def sum-pairs (partial map sum-of))
(defn concat-zeroes
[coll]
(concat coll (repeat 0)))
(def compress-left
(comp
concat-zeroes
sum-pairs
pair-partitions
partition-number-sequences
remove-zeroes))
(def move-row-left (comp (partial take 4) compress-left))
(def move-row-right (comp reverse move-row-left reverse))
(def move-grid-right
"Moves an entire grid to the right"
(partial map move-row-right))
(def move-grid-left
"Moves an entire grid to the left"
(partial map move-row-left))
(def transpose (partial apply map list))
(def move-grid-down
"Moves an entire grid down"
(comp transpose move-grid-right transpose))
(def move-grid-up
"Moves an entire grid up"
(comp transpose move-grid-left transpose))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment