Skip to content

Instantly share code, notes, and snippets.

@Harrisonl
Created December 5, 2018 23:57
Show Gist options
  • Save Harrisonl/14670df6cd91407b7b29b32c68ba9567 to your computer and use it in GitHub Desktop.
Save Harrisonl/14670df6cd91407b7b29b32c68ba9567 to your computer and use it in GitHub Desktop.
Day2 Part 1
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