Created
December 5, 2018 23:57
-
-
Save Harrisonl/14670df6cd91407b7b29b32c68ba9567 to your computer and use it in GitHub Desktop.
Day2 Part 1
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
data LetterGroup = TwoChar | |
| ThreeChar | |
deriving (Show, Eq, Ord) | |
-- PROBLEM 1 | |
-- Call This | |
calcCheckSum :: [ID] -> Int | |
calcCheckSum = foldl (*) 1 . map length . groupSort . concat . map (nub . repeats) | |
twoOrThree :: [LetterGroup] -> [Char] -> [LetterGroup] | |
twoOrThree acc [_, _] = TwoChar : acc | |
twoOrThree acc [_, _, _] = ThreeChar : acc | |
twoOrThree acc _ = acc | |
repeats :: ID -> [LetterGroup] | |
repeats = foldl' twoOrThree [] . groupSort | |
groupSort :: Ord a => [a] -> [[a]] | |
groupSort = group . sort |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment