Created
August 8, 2019 07:52
-
-
Save craftybones/807079365c8837945a22de8f63b4020c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import Data.List | |
groupN :: Int -> [a] -> [[a]] | |
groupN _ [] = [] | |
groupN 0 _ = undefined | |
groupN n x = take n x : groupN n (drop n x) | |
transpose :: [[a]] -> [[a]] | |
transpose ([]:_) = [] | |
transpose x = map head x : (transpose (map tail x)) | |
removeZeroes = filter (/= 0) | |
pairPartitions = concatMap (groupN 2) | |
sumOf = foldl (+) 0 | |
sumPairs = map sumOf | |
concatZeroes = (++ repeat 0) | |
compressLeft = concatZeroes . sumPairs . pairPartitions . group . removeZeroes | |
moveRowLeft = (take 4) . compressLeft | |
moveRowRight = reverse . moveRowLeft . reverse | |
moveGridLeft = map moveRowLeft | |
moveGridRight = map moveRowRight | |
moveGridUp = transpose . moveGridLeft . transpose | |
moveGridDown = transpose . moveGridRight . transpose | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment