Day 2, parts 1 & 2: Initial solutions.
This commit is contained in:
parent
873455cab8
commit
a29ce36899
|
|
@ -0,0 +1,14 @@
|
||||||
|
#! /usr/bin/env stack
|
||||||
|
-- stack --resolver lts-12.20 --install-ghc script
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import Control.Arrow ((&&&))
|
||||||
|
import Data.List (group, sort)
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = interact $ show . \input ->
|
||||||
|
let codes = lines input :: [[Char]]
|
||||||
|
counts = map (map (head &&& length) . group . sort) codes :: [[(Char, Int)]]
|
||||||
|
twos = length $ filter (any ((== 2) . snd)) counts
|
||||||
|
threes = length $ filter (any ((== 3) . snd)) counts
|
||||||
|
in (twos, threes, twos * threes)
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
#! /usr/bin/env stack
|
||||||
|
-- stack --resolver lts-12.20 --install-ghc script
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
loopRight :: b -> (b -> Either a b) -> a
|
||||||
|
loopRight b f = case f b of
|
||||||
|
Left a -> a
|
||||||
|
Right b' -> loopRight b' f
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = interact $ show . \input ->
|
||||||
|
let codes = lines input :: [[Char]]
|
||||||
|
in loopRight ([], codes) $ \(seen, c:cs) ->
|
||||||
|
case filter (`isSimilarTo` c) seen of
|
||||||
|
[] -> Right (c:seen, cs)
|
||||||
|
(x:_) -> Left (c, x, foldMap (\(a,b) -> if a == b then [a] else [])
|
||||||
|
(zip c x))
|
||||||
|
|
||||||
|
isSimilarTo :: (Eq a) => [a] -> [a] -> Bool
|
||||||
|
(x:xs) `isSimilarTo` (y:ys)
|
||||||
|
| x == y = xs `isSimilarTo` ys
|
||||||
|
| otherwise = xs == ys
|
||||||
|
_ `isSimilarTo` _ = False
|
||||||
|
|
@ -0,0 +1,250 @@
|
||||||
|
asgwdcmbrkerohqoutfylvzpnx
|
||||||
|
asgwjcmbrkejihqoutfylvipne
|
||||||
|
asgwjcmbrkedihqoutvylizpnz
|
||||||
|
azgsjcmbrkedihqouifylvzpnx
|
||||||
|
asgwucmbrktddhqoutfylvzpnx
|
||||||
|
asgwocmbrkedihqoutfylvzivx
|
||||||
|
aqgwjcmbrkevihqvutfylvzpnx
|
||||||
|
tsgljcmbrkedihqourfylvzpnx
|
||||||
|
asgpjcmbrkedihqoutfnlvzsnx
|
||||||
|
astwjcmbrktdihqrutfylvzpnx
|
||||||
|
asgwjcmbrpedhhqoutfylvzynx
|
||||||
|
xsgwjcmbrkedieqowtfylvzpnx
|
||||||
|
asgwjcmbvkedihfoutnylvzpnx
|
||||||
|
asgwjcmtrkedihqouafylvzcnx
|
||||||
|
asgwjcmbrkedihqoutfylvxpvm
|
||||||
|
usgwjcmbrkedihqortfyuvzpnx
|
||||||
|
asgwjcmbrwedihqoutfylizpix
|
||||||
|
asgrjcvbrkedixqoutfylvzpnx
|
||||||
|
asgwjcmbrogdihqoutfelvzpnx
|
||||||
|
aggwjcmbrkesihqoutoylvzpnx
|
||||||
|
asgtjccbrkedihqoutfrlvzpnx
|
||||||
|
asgcucmbrbedihqoutfylvzpnx
|
||||||
|
esgwjcmbrkedihqsutfylvzcnx
|
||||||
|
asgwjcmbrkedrhqoutfyobzpnx
|
||||||
|
mngwjcbbrkedihqoutfylvzpnx
|
||||||
|
asgwjcrbrkeoihqyutfylvzpnx
|
||||||
|
apgwjcmbrkednhqogtfylvzpnx
|
||||||
|
asgwjcwbrkedihqoutfylplpnx
|
||||||
|
asgwjcmbrkfdihqoutfxlvzpyx
|
||||||
|
aegwjcmbrkedihqoutfylbxpnx
|
||||||
|
asgljcmbrkedixqoutaylvzpnx
|
||||||
|
aigwjcmbrkedihqouhfylvzpex
|
||||||
|
asgwjbmbrkedihqoutfylfzpnp
|
||||||
|
asgwjcmzroedihqoutcylvzinx
|
||||||
|
asgwjcwbrieuihqoutfylvzpnx
|
||||||
|
aagwjcmbrkedjhqdutfylvzpnx
|
||||||
|
ahgwjcmbrkedihqsutfylvzpfx
|
||||||
|
asgwjcmbrkedihzosttylvzpnx
|
||||||
|
aegwjcmbrkedioqnutfylvzpnx
|
||||||
|
asgwjcmbykidihqoutfysvzpnx
|
||||||
|
asgwkcxbrkeddhqoutfylvzpnx
|
||||||
|
ashwjcmbrkeeihqoutfylvzknx
|
||||||
|
acgwjcmbrqedihqoqtfylvzpnx
|
||||||
|
asgwjcmtrkedihooutfylszpnx
|
||||||
|
asgwjcmbrkmdihqfutrylvzpnx
|
||||||
|
asgwjcmbrkedihqoutjylvapnn
|
||||||
|
asgwjcmbwkedihqoutkylkzpnx
|
||||||
|
asgwjrmbrkedihqoutfycnzpnx
|
||||||
|
asgwtcmbrkedihqoqtfylozpnx
|
||||||
|
asgajcmbrkedihqoutuylvzpny
|
||||||
|
asgwjcmbykedihqoutfylfzpwx
|
||||||
|
asgwjcsbrkedihpoutfylvvpnx
|
||||||
|
hsdwjcmbrvedihqoutfylvzpnx
|
||||||
|
asgwjcmbrkedihqoutfdmszpnx
|
||||||
|
adgwjcmbrtidihqoutfylvzpnx
|
||||||
|
augwjcmbriedihqoutgylvzpnx
|
||||||
|
asgwjvmbreedihqoutfllvzpnx
|
||||||
|
asgwjcnbfkedihqoltfylvzpnx
|
||||||
|
asgwjcmbykddihqoutqylvzpnx
|
||||||
|
ajgwjcmbrkedihqoutfylvpvnx
|
||||||
|
asgwjcmbrkydihqoutfylszpnl
|
||||||
|
xsgwjcmbrkqdihqoutfylvkpnx
|
||||||
|
asgwjcmbrkedimqoutfklvzknx
|
||||||
|
csgwjbmbrkedihqoftfylvzpnx
|
||||||
|
asgwjcmbjkedihjoutfylvzpnn
|
||||||
|
asgwjcmprkedihqoulfalvzpnx
|
||||||
|
asgwjcmbrvediqqoutfyuvzpnx
|
||||||
|
asgwjambrkedhhqoutkylvzpnx
|
||||||
|
asgejcmbrkidihqoutfylvzpnk
|
||||||
|
hsiwjcmbrkedihqoutfylvzpnq
|
||||||
|
asswjczbrkedihqoutfylczpnx
|
||||||
|
asgwjnmbrkedyhzoutfylvzpnx
|
||||||
|
asgwscmbrkedihqoutfklvlpnx
|
||||||
|
asgwlcmbrktdihqoutfylvzpax
|
||||||
|
asfwjcmerkedihqoutfylvipnx
|
||||||
|
asgwjcmbrkeditqoeafylvzpnx
|
||||||
|
asgwgcmbrkesihqoutfylyzpnx
|
||||||
|
fsgwjcmbrkedihqouvfyavzpnx
|
||||||
|
asgwjcmbrpedwhqoutfylmzpnx
|
||||||
|
asgwjcmbrkzdzhqoucfylvzpnx
|
||||||
|
asgwjcmnrketmhqoutfylvzpnx
|
||||||
|
asgwjcmbrkedihxoutsylvzpnh
|
||||||
|
asgwjcobrkedihqoutfrlvzpox
|
||||||
|
asgwjcmbrkedihqootfylxzpox
|
||||||
|
asgjjcmcrkedihqoutfylmzpnx
|
||||||
|
lsgwjcmbrkedihqoutfyqvzunx
|
||||||
|
asgwjcmbrwedihqoutoylvzpnu
|
||||||
|
aszwjcmbtkedihqoutfylczpnx
|
||||||
|
asgwjcmbykedihqoutfylvgpex
|
||||||
|
asgijcmbrkedilqoutkylvzpnx
|
||||||
|
astwxcmzrkedihqoutfylvzpnx
|
||||||
|
akgwjcmbnkedihqfutfylvzpnx
|
||||||
|
asgwjcmbrqndivqoutfylvzpnx
|
||||||
|
asgwjrmbrleqihqoutfylvzpnx
|
||||||
|
asgwjcmbrkevihqoutfxlvzpvx
|
||||||
|
asbwjcmbrkedihqoutfelvwpnx
|
||||||
|
asewjcbbrkmdihqoutfylvzpnx
|
||||||
|
asgwjcmbrkeaihxoutfylpzpnx
|
||||||
|
asgwjzmbrkedihqrotfylvzpnx
|
||||||
|
asgwjcmbrkedihqoutgdxvzpnx
|
||||||
|
asgwjcwbrkmdihqoutfylvzlnx
|
||||||
|
asgwjcmbrkegihqoutfylrzpax
|
||||||
|
ajgwjcmbrkegihqhutfylvzpnx
|
||||||
|
asgwjcmbrzedihqhutfylvkpnx
|
||||||
|
asgwjcmwrkedihqouhfylkzpnx
|
||||||
|
aygwjcmbrkedihqoutfdlvzpnr
|
||||||
|
asgwjcmbrkednhqoutiylvypnx
|
||||||
|
aqgwjcmbrkezihqoutfylvzonx
|
||||||
|
bsgwjcmbrkedihqouhfylvzsnx
|
||||||
|
asgwjcmcrkedihqokyfylvzpnx
|
||||||
|
asgsjcmbrkewiyqoutfylvzpnx
|
||||||
|
asgwpcmbrkejihqoutfylzzpnx
|
||||||
|
asgwjumbrkedbeqoutfylvzpnx
|
||||||
|
asgwjcmbrkedihpoutqylqzpnx
|
||||||
|
awgwjcmbrredihqoutfylvzpna
|
||||||
|
asgwjsmbraedihqoutfylvzpvx
|
||||||
|
asgwncmbrkedihqoutfyljzrnx
|
||||||
|
asgwncmbrkedihqohtfylvzonx
|
||||||
|
asgwjcmbrkedihqlutfylvypux
|
||||||
|
asgwjcmbbkedihooutfylkzpnx
|
||||||
|
asghjcmsryedihqoutfylvzpnx
|
||||||
|
asgwjcmbrkevihqoulfzlvzpnx
|
||||||
|
asggjcmbrkedizqoutfylvzknx
|
||||||
|
asbwjcmbriedihqoutfylvmpnx
|
||||||
|
asgwjcmbrkedqbqoutfylvzenx
|
||||||
|
asgwjcmprkedihqoutfylvzknp
|
||||||
|
asgwjcmbrkerihqoutfwlvzpno
|
||||||
|
asgwjcmvrkesihqoutrylvzpnx
|
||||||
|
asgzjcmbrkedihqoutfnlvbpnx
|
||||||
|
asfwjcmbrkhdihqoutfylpzpnx
|
||||||
|
asgwjcmbskedihqdutfyyvzpnx
|
||||||
|
asgwjcmzrkedihqoutcylvzinx
|
||||||
|
asgwjcmbrkedibqoutfylvjonx
|
||||||
|
asgwjcmbrbedihqoutfylmzbnx
|
||||||
|
asgwjcmbrkedhhqoutmylczpnx
|
||||||
|
asgwjcmbrkbgihqoutzylvzpnx
|
||||||
|
asgwjcfbrkedihqoupfyxvzpnx
|
||||||
|
asiwjcmbzkedihqoutfyluzpnx
|
||||||
|
asvwjcmbrkedihqoitfylvzpns
|
||||||
|
asgwjcmxikedihqoutfyevzpnx
|
||||||
|
asgwjcmbrkedioqoutfylvzwox
|
||||||
|
asgwjcmbrkedivqoutjyuvzpnx
|
||||||
|
asgwjcmbkkydihqrutfylvzpnx
|
||||||
|
asgwjcmbrkxdiuqoutfylvopnx
|
||||||
|
asgwjcmbrkedihqouthylvzpra
|
||||||
|
asgwjcmbrzedimloutfylvzpnx
|
||||||
|
asgwjcmbrkedmhqoulfytvzpnx
|
||||||
|
asgwjcmbrkzdihqrutfysvzpnx
|
||||||
|
ssgwjcmxrkedihqoutftlvzpnx
|
||||||
|
asgwjcmbrkedihqoutfajvzynx
|
||||||
|
asgwjcmbrkqdihqxuufylvzpnx
|
||||||
|
asmwjcabrkedihqouxfylvzpnx
|
||||||
|
asgwjcmbrkeeihqoatfycvzpnx
|
||||||
|
asgwjcjbrgedjhqoutfylvzpnx
|
||||||
|
asgljcmtrkedihqoutoylvzpnx
|
||||||
|
asgwjcmbrkedigqouzfylvzpvx
|
||||||
|
ajgvjcmbkkedihqoutfylvzpnx
|
||||||
|
asgwjcmbrkedihqtugfygvzpnx
|
||||||
|
asgbjcmbrkedihboftfylvzpnx
|
||||||
|
asgwjwmbrkedihqontfylhzpnx
|
||||||
|
asgwjfmhrkedihqoutfylvqpnx
|
||||||
|
asgwjxmbrkedihqoutzylvzpnj
|
||||||
|
asgwjcrlrkedihqoutfylvzpsx
|
||||||
|
aygwjcmbrkedihqoutsylvzdnx
|
||||||
|
zsgwjcmbrkedihjogtfylvzpnx
|
||||||
|
asgwjxmbrkegihqoutfylvopnx
|
||||||
|
asgwjcmbrkedihqhutfylvzcnr
|
||||||
|
asgwicmbrkewihvoutfylvzpnx
|
||||||
|
asqwjcmbvkedihqoutfylvzknx
|
||||||
|
asgwjcmbrkedihqoktfyevzpnu
|
||||||
|
asgwjcmbrkudihqoutfylqzznx
|
||||||
|
asgwjdmbrkedihqoutfylvvdnx
|
||||||
|
asgwjcmbrkwmihqautfylvzpnx
|
||||||
|
asgwjcmbrxedihqoctfyldzpnx
|
||||||
|
asgwjdmbrkedjhqoutfyfvzpnx
|
||||||
|
asgwjcmtrzedihqoutfylvzpnm
|
||||||
|
bpgwjcmbrmedihqoutfylvzpnx
|
||||||
|
asgwjctbrkedihqoqtfynvzpnx
|
||||||
|
askhjcmbrkedihqoutfylvzrnx
|
||||||
|
asgkjcmblkehihqoutfylvzpnx
|
||||||
|
asgwjjmbrkedvhqoutfhlvzpnx
|
||||||
|
asgwjcmbrkedihqoupzylvzknx
|
||||||
|
asgwjcmbukedchqoutfylizpnx
|
||||||
|
askwjcmdrkedihqoutwylvzpnx
|
||||||
|
asgwjcmbtkcdihloutfylvzpnx
|
||||||
|
asgwjcmbrkedwgqoutvylvzpnx
|
||||||
|
asmwjcmbrkedihqoutfylozpnc
|
||||||
|
asgwjcmbriedibqouofylvzpnx
|
||||||
|
asgnjcmcrkedihqoupfylvzpnx
|
||||||
|
asgzjcmbrksdihqoutiylvzpnx
|
||||||
|
asgwjcrbkkedihqouafylvzpnx
|
||||||
|
asgwjcmbkkvdihqqutfylvzpnx
|
||||||
|
astwjcqbrkedihqoutfylvzpvx
|
||||||
|
asgwjcmhrkehihqoutfylvzvnx
|
||||||
|
asgwjcmbraeduhqoutmylvzpnx
|
||||||
|
asgwjcmbrkedihquutnylvzptx
|
||||||
|
asgwjcmbrkedilqoftfylvzpnz
|
||||||
|
akgwjmmbrkedihqoutfylxzpnx
|
||||||
|
asgwjcmbrkhxikqoutfylvzpnx
|
||||||
|
asgcjcmetkedihqoutfylvzpnx
|
||||||
|
fsgwjcmsrkedihooutfylvzpnx
|
||||||
|
gsgwjcmbrkedihdoutfylvzdnx
|
||||||
|
asgwtccbrkedihqoutfylvwpnx
|
||||||
|
asuwjcmbrkedihqcutfylvzpox
|
||||||
|
asgwacmbrkodihqlutfylvzpnx
|
||||||
|
asgwjcmbrkediuqoutfylqhpnx
|
||||||
|
asgwjcmbrkwdrhqoutfylvzpno
|
||||||
|
angwjcsblkedihqoutfylvzpnx
|
||||||
|
aigwjcmbyoedihqoutfylvzpnx
|
||||||
|
adgwjcmbrkedihqtutfylyzpnx
|
||||||
|
asgwjzmbrkeeihqputfylvzpnx
|
||||||
|
asgwjcmbrkwdihqoutfylvzpwc
|
||||||
|
asgpjcmbrkgdihqbutfylvzpnx
|
||||||
|
osgwjmmbrkedijqoutfylvzpnx
|
||||||
|
asgjjcmbrkkdihqoutfylvzynx
|
||||||
|
asgwjcnerwedihqoutfylvzpnx
|
||||||
|
azgwhcmbrkedicqoutfylvzpnx
|
||||||
|
asnwjcmbrsedihqoutfylvzpnm
|
||||||
|
hsgwjcmgrkedihqoutfilvzpnx
|
||||||
|
asgwscmbrkjdihqoutfylvzpnm
|
||||||
|
asgbjbmbrkedhhqoutfylvzpnx
|
||||||
|
aswwjcmtrkedihqjutfylvzpnx
|
||||||
|
asgwicmbrbedihqoutfylvzpnm
|
||||||
|
asgwjcubrkedihqoutfylvbnnx
|
||||||
|
asvwjcmbrkehihqoutfylhzpnx
|
||||||
|
gsgwjcmbrkedihqoutsklvzpnx
|
||||||
|
asgwjcubikedihqoitfylvzpnx
|
||||||
|
asgwjpmbskedilqoutfylvzpnx
|
||||||
|
aigwjcmbrxedihqoutyylvzpnx
|
||||||
|
asgwjcpbrkedihxoutfynvzpnx
|
||||||
|
asgwjcmbrkegihqoutfklvzcnx
|
||||||
|
asgwjvubrkedjhqoutfylvzpnx
|
||||||
|
asgwjcabrkedihqoutfyivzplx
|
||||||
|
asgwjcxbrkedihqgutfylvepnx
|
||||||
|
asgwlcmbrkedihqoutqylvwpnx
|
||||||
|
asgwjhmbrkydihqhutfylvzpnx
|
||||||
|
asgwjcmbrkedihqoutfylwzone
|
||||||
|
asgwycmbrkadihqoutuylvzpnx
|
||||||
|
asgwjcybrkedihqoftfylvzpne
|
||||||
|
asgwjcmnrkedihrodtfylvzpnx
|
||||||
|
asgwicmwrkedihqoutfyovzpnx
|
||||||
|
aqgwjlmbrkedilqoutfylvzpnx
|
||||||
|
asgwjcmzskwdihqoutfylvzpnx
|
||||||
|
asgwjcmdrkebihqoutfylvjpnx
|
||||||
|
asgwjcmbrkpdihqoutfylxzphx
|
||||||
|
asgwjcmbrkedixqoutlylfzpnx
|
||||||
|
asgwjcmbrkadihqoutfylvlpdx
|
||||||
|
asgejcmqrkedyhqoutfylvzpnx
|
||||||
|
asgwjcmvroedihpoutfylvzpnx
|
||||||
|
asgwjcmxrkedihqoutfyivzpmx
|
||||||
Loading…
Reference in New Issue