This commit is contained in:
Gattix 2022-12-03 16:51:46 +01:00
parent 5f2a243e85
commit 66b1e7128b
3 changed files with 323 additions and 0 deletions

17
2022/day03/day03.hs Normal file

@ -0,0 +1,17 @@
import Data.List
import Data.List.Split
import Control.Arrow
main :: IO ()
main = do
input <- lines <$> readFile "input"
print $ (day3a &&& day3b >>> sum *** sum) input
day3a :: [String] -> [Int]
day3a = map $ convert . uncurry intersect . (nub *** nub) . (flip splitAt <*> flip div 2 . length)
day3b :: [String] -> [Int]
day3b = map (convert . foldl1 intersect) . chunksOf 3
convert :: String -> Int
convert = (\x->if x>90 then x - 96 else x - 38) . fromEnum . head

300
2022/day03/input Normal file

@ -0,0 +1,300 @@
WVHGHwddqSsNjsjwqVvdwZRCbcJcZTCcsZbLcJJsCZ
hngprFFhFDFhrDpzzQDhtnBJJRJZbZvTcvbfRCJfBRcBJl
DmptngtFwvvMmwmm
HFddrJnLdqtHBMQBmmVm
gbvNsbhsvQtmZTbQPT
vDshDlczcDhcssscwzQwslLJrSJLpqrrzpnCrSfLSnqq
pDGQDSpFDGzFDQSJqzDhjhQMTjTrwTstbTBTjTtLtbTMBT
zgzVNHHgMwMLbLNB
WRWPgdHCZccggJmJGzJmzGhGCD
sVJNlhldShpdpnnwVnwCwtwggt
WLFFcHWQLPPZQCgtnCgmbtbHwt
MPLWzRMMcGgRrWNDpSSSfDflMlTd
BBMZJcgBRjCZZzBpSvHQvbLvvHCQLQ
VlVTFwDTVGnfWSQPtsDPbvrpDS
wWdqhWlwGVfGwlfTVqFWfWWjzZZBJmMZMNdzZJMpjzNjgJ
FBWFphQBmDmpmMSpDWVcVcvsPcRbrjPMcMsr
HHtdnHnwNCHCTJRTPTzrbvVbcVRr
lHqHwlnlqnGCNGGmWDvvZfpZvG
mfVtmPtsccMmHcHCFfmhVmnpgZLbWPZqWnpqZbZWpgPW
zzvwBrzdQDvpZJfQJZJpLf
BrTBwRdNcfNmfStc
sTlhFLfZTTLcfsLlLDZflvQvRNqRJFNvRMRN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