Created
February 28, 2019 18:53
-
-
Save craftybones/42f180cf753db07b6694de87f4182ece to your computer and use it in GitHub Desktop.
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
(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