GitLab's annual major release is around the corner. Along with a lot of new and exciting features, there will be a few breaking changes. Learn more here.

Commit c1283581 authored by Neil Smith's avatar Neil Smith
Browse files

Done day 6

parent 9ced9f21
# This YAML file describes your package. Stack will automatically generate a
# Cabal file when you run `stack build`. See the hpack website for help with
# this file: <https://github.com/sol/hpack>.
name: advent06
synopsis: Advent of Code
version: '0.0.1'
default-extensions:
- AllowAmbiguousTypes
- ApplicativeDo
- BangPatterns
- BlockArguments
- DataKinds
- DeriveFoldable
- DeriveFunctor
- DeriveGeneric
- DeriveTraversable
- EmptyCase
- FlexibleContexts
- FlexibleInstances
- FunctionalDependencies
- GADTs
- GeneralizedNewtypeDeriving
- ImplicitParams
- KindSignatures
- LambdaCase
- MonadComprehensions
- MonoLocalBinds
- MultiParamTypeClasses
- MultiWayIf
- NamedFieldPuns
- NegativeLiterals
- NumDecimals
# - OverloadedLists
- OverloadedStrings
- PartialTypeSignatures
- PatternGuards
- PatternSynonyms
- PolyKinds
- RankNTypes
- RecordWildCards
- ScopedTypeVariables
- TemplateHaskell
- TransformListComp
- TupleSections
- TypeApplications
- TypeFamilies
- TypeInType
- TypeOperators
- ViewPatterns
executables:
advent06:
main: advent06.hs
source-dirs: src
dependencies:
- base >= 2 && < 6
- text
- attoparsec
- containers
\ No newline at end of file
-- import Debug.Trace
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import Data.Attoparsec.Text
-- import Data.Attoparsec.Combinator
import qualified Data.Set as S
main :: IO ()
main =
do text <- TIO.readFile "data/advent06.txt"
let groups = successfulParse text
-- print groups
print $ part1 groups
print $ part2 groups
part1 groups = sum $ map (S.size . S.unions) groups
part2 groups = sum $ map (S.size . intersections) groups
intersections :: Ord a => [S.Set a] -> S.Set a
intersections group = foldl S.intersection (head group) group
-- -- Parse the input file
blankLines = skipMany1 endOfLine
personP = S.fromList <$> many1 letter
groupP = sepBy1 personP endOfLine
groupsP = sepBy1 groupP blankLines
-- successfulParse :: Text -> [Passport]
successfulParse input =
case parseOnly groupsP input of
Left _err -> [] -- TIO.putStr $ T.pack $ parseErrorPretty err
Right groups -> groups
gwlcpbtxmiezd
xwlcpbtzimgdk
tbiwmpcgzdxo
ygzdbpjxncfwimt
icb
xqhf
mlpjsqwv
dvjqsipz
slqpvj
waxcqvufpkeld
udkvxbjaglpq
gkxfpqvudhjl
uivpdozsnrqkxmtl
tzhercs
cgxujw
dianpfvbk
vwynik
obrut
gmbza
atm
fvjnryuk
scihpabjgdxo
kpeir
rikpe
rpiek
inwtuxevsacyqg
cvteaqoylwknxfgui
ewqvugcxyntai
xbsymjfvh
hmsbyvxj
vsyxmjhb
atfckhz
wm
p
egdbwvl
jproey
zgatorfjh
fbxogarc
sgvzafwj
feagpnqlyumdi
wfhvabg
c
c
c
j
c
egl
uel
le
jcodp
jpdc
jmcpd
nfz
zpiyn
nz
knhz
rxl
dr
g
suj
teo
cuzq
fzsw
pqgdsbmuvechjxfz
auovygnkldfbwr
jmos
msuj
z
vb
wn
dvyoixczmh
vmyxoczdi
ixydonzck
icwyeoxdz
jafpextioch
pztsoxefcymrgjikhda
opecfhxjtuia
icuhjoaetpfx
ipxyojqwegvu
bvhtiogwxjqdue
wongurjizvfekxmsqlac
xdvgoiquwej
unzvtlbaxmfri
cfosmwtdpyziekhajgq
lsipkqmohvztfcgb
cvqtblhmpfgsozk
mpvsbflqczkhgot
wg
gw
wg
wg
dpeyclxofhk
pgxheckmylod
xkpmcosuyeldh
yvoxhekgcpdl
lrhndwaoekycpx
hva
ah
hat
ha
zfqj
zjyqf
qjfz
qjfz
qfzj
fvoaxgj
xfoygja
gehvyapz
gwpzyvahe
zhavpegy
viursfc
vucfr
mxstvocyufr
gnflvqdzkcrwhupa
yqdxh
yhqxd
yhqtdx
dyqhjzx
rkp
orkph
ckpr
ym
epytqgr
jvdmy
dtkcjulsy
tujysdckl
mhgavu
ghvu
uvhg
klqxbejfmgtrausdpy
mjayepflubdksgqtxr
jmakegrybfxutspldq
tpdyneqlmrkajxusgfb
vlmi
lxhz
bpv
e
mu
kme
cnxwtbigkedzsyjr
ihsngtewzjukxcrd
cegsxnwydzitkuj
vpdlnsiazkejgcwxto
wizfnsgqtxekdjrc
pojbrzvhnltydmswqga
gudzjlwynbriaqvsphto
ldtacrhgopvqzywbsjn
rvpbylxcuajdh
rxwjpbedvuayl
yavrpdlxjibu
riydhaplbfcuvxj
ibpayxruvdlj
gojpz
hmvkeqbxr
znwovmahqdcefrjbs
crnjswagzqmevhdofb
sfchdgxqjmzviebonarw
zoqbcwdvnshfearjmt
snhazkomqjvrcbflwpdye
au
au
fbu
oglu
yzwxtvuhdaeo
bridg
ljndxc
nxjc
cjnx
dyrwejnmuqpxolakgbzhv
vxmnpagycwquzlhdojrsebk
umhalvgjenrxpydwzkobtq
nytrhgplwdjkioumbexvqaz
uyakmhxqifbdjer
tmeqpsfahxoruw
l
y
xgw
paxdsuof
xw
ztvo
ixu
lrnkj
zxq
foxkjaehwqcntiu
fojweunxikahtcq
hjtnwcuifkxqeao
oqjxwicklaehtupnmf
jachtnuqxwoekfi
btq
qtbv
ra
yasr
ncmvroaz
pevfcuo
rivmwztqy
gdmlczw
mpacxyolh
lcrmi
lgkecqdtm
rlktmdcf
itkzmv
kizt
ksxgfjrtvdqybwoze
jgzydsxtvwbforkqe
xtfmoew
gzldprhy
mecgavlynobxupi
jyohgertfnmuxz
rakfugnvxpi
funvgpia
xfurihg
guhdrqix
qo
q
qv
mrqp
cuseonqthxpavmgd
ynhazdmkfivjxwope
hzejxiavpnkodlfm
zbexajlphdmvkno
dotnhqgu
nguqrv
unoigqr
ncuqgp
wfinrjsmlxzchqpv
hqwljsfkxnmizpcv
qiswhmrpxcnfjzvl
cxljqizvnwhsmpf
qhwsilbczxfpjmnv
n
thes
s
wpkadjgorxcy
mue
upwxeatcm
mpwectyud
ewvtumpyc
pglamhfkcsyoeb
hfakeosglmcpyb
gesmyloacpfhkb
ksemychfgalpbo
fgohpcklsemayb
bn
unb
mbdn
bun
zmwfyakq
swaj
twrva
rbkcgzqvp
oumthkfnia
wsadpbj
biznahjxc
azblmj
e
er
r
ge
tb
nzq
cldif
hlswofngtjda
ajvodlhtsw
whaltsodj
fe
frcbep
fe
cgjlhspvnmiut
jgptuchmsnilv
lcdnguvhsjmxipt
psugwjctmihvnl
r
ir
rwk
rlgj
r
ypakce
pyjxchkeon
cpgyke
ksilwgqtud
kisldgtqwu
zslgqtikduw
qudilskjwgt
jquan
nou
szfq
qszf
fqzs
sqfz
fqsz
kriwjoyabgslfmx
kqjdhnuei
tocqzagpnbyd
sxunfeaicptv
r
yr
tru
d
d
tkv
taondlyrxhv
nhbciefzudw
gsmpjqk
kbrswhqj
bhqswkjr
qbrjhskw
hbkrqjws
qbkujrswhn
ruaqvlfb
fduniqemlgab
bkaqlfu
pesctg
tjpesygc
mpcgvst
cjsbwptkg
gsphtc
jwq
yjpkzi
wj
qujw
j
v
v
v
v
vg
ynwlevxsopbuc
luepovcwbnsy
nwvcusyplokeb
jscybopflvuenw
eoysncwuvblp
qhjtyuxdbcgsfomnl
tlyfnqbmusghdjcxo
htnfqbcmujsxlogdy
buysgfjtnchdmqxolr
dr
vri
rmunz
oashgr
kmlvrd
dqhsjgrak
qxvlgb
xgpqbu
tgenibcmq
f
f
f
fy
vyukhwopcxbmjgfq
xchljnpgryq
b
b
ewmlqdzgtsaf
zvfrbaysleqogtwm
fqatklgwumhzes
lzgsfmtiweaqcx
sqxazpginrvbmoflectkhyd
igkxqsdahmepcybrfltzov
qf
d
q
uhvndserfgt
cmdethsfurnygv
tfnvrugeshd
gfrsntdhveu
fenhsdvtprgu
nkm
km
mk
dw
z
x
ud
vi
sleyfmcvigp
ytneopvgcms
c
h
j
r
h
jvxmidzkg
nqjuzkvcxhpid
dzjkxgvifm
hwgzm
ucaewrs
ywjkgxt
tewjlngvszk
tnjkzve
agjhkznvesqwrt
kwztvjnaedl
jpyteikxobncvzm
uxcpz
pucxz
xpbczu
xzcup
uzpcx
cfxlvkiswmgzrtjuq
kfxcqtnmrlzjswvg
hxetzclbjfmvwsrgqk
fpaxlvbzwnqkgsj
xczqlbkwgapyvsnj
bwzalgjsnqpxkvr
jnskawbxlpzvgqe
wsajkvygnqbzxilp
zuhimpjlbfogqkn
ophznvgmfuiakj
njhkpfiomguz
okufhjdgznipm
fpsmed
shgef
mfse
esqfv
xkj
nk
ndc
j
gh
wkeocxgtds
xekgsowdt
n