Custom Customs


Fork me on GitHub
2020-12-06

Day 06: Custom Customs

Description:
--- Day 6: Custom Customs ---

As your flight approaches the regional airport where you'll switch to a much larger plane, customs declaration forms are distributed to the passengers.

The form asks a series of 26 yes-or-no questions marked a through z. All you need to do is identify the questions for which anyone in your group answers "yes". Since your group is just you, this doesn't take very long.

However, the person sitting next to you seems to be experiencing a language barrier and asks if you can help. For each of the people in their group, you write down the questions for which they answer "yes", one per line. For example:

abcx
abcy
abcz

In this group, there are 6 questions to which anyone answered "yes": a, b, c, x, y, and z. (Duplicate answers to the same question don't count extra; each question counts at most once.)

Another group asks for your help, then another, and eventually you've collected answers from every group on the plane (your puzzle input). Each group's answers are separated by a blank line, and within each group, each person's answers are on a single line. For example:

abc

a
b
c

ab
ac

a
a
a
a

b

This list represents answers from five groups:

The first group contains one person who answered "yes" to 3 questions: a, b, and c.
The second group contains three people; combined, they answered "yes" to 3 questions: a, b, and c.
The third group contains two people; combined, they answered "yes" to 3 questions: a, b, and c.
The fourth group contains four people; combined, they answered "yes" to only 1 question, a.
The last group contains one person who answered "yes" to only 1 question, b.

In this example, the sum of these counts is 3 + 3 + 3 + 1 + 1 = 11.

For each group, count the number of questions to which anyone answered "yes". What is the sum of those counts?

--- Part Two ---

As you finish the last group's customs declaration, you notice that you misread one word in the instructions:

You don't need to identify the questions to which anyone answered "yes"; you need to identify the questions to which everyone answered "yes"!

Using the same example as above:

abc

a
b
c

ab
ac

a
a
a
a

b

This list represents answers from five groups:

In the first group, everyone (all 1 person) answered "yes" to 3 questions: a, b, and c.
In the second group, there is no question to which everyone answered "yes".
In the third group, everyone answered yes to only 1 question, a. Since some people did not answer "yes" to b or c, they don't count.
In the fourth group, everyone answered yes to only 1 question, a.
In the fifth group, everyone (all 1 person) answered "yes" to 1 question, b.

In this example, the sum of these counts is 3 + 0 + 1 + 1 + 1 = 6.

For each group, count the number of questions to which everyone answered "yes". What is the sum of those counts?

Input:
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
n
n
n

rpgonuykqjawhfdxcmzvbe
mhtrxudpnvbezawcyqjgkf

wtoveydlszxngqcbiuk
glsktqomjwrebz
hwbgulqtzoeackyvs

drfxcnjqsyug
dsfrniycubx
cyshxnkdrfuzv
cswmnxaylfrdtu
cduymsxfpnr

htnpxifrlsmgev
ohwmykctdnzquj
htmsfbanlx

sigvmu
gvism
gisqmvprlw
aigvsdm
svpmgli

msbeiuotwyrq
ebykoiswt
wkfyeitaonsb
wiogepskytvb

xcimgdsvfkhzonlb
fkdsbcohnizgvlmx
cizlnxdkghbmosfv

h
a
a
h
b

kyqg
sohnwprx
zmb

msw
mws
swm
msw
wsm

xopjrmh
plrshdmwoax
pxiromh
xmpbhorj
ijxhpmor

acempwkqxoglu
puhqcvwadebsxj

xaiwnyl
yowxn

lbynjvihxe
dojvbhlinyx
hxyvbijnel
jlxihnvby
xhnbijvyl

gkewxnjbc
sztpavcrkyqmndhi
cguknlo

ywgpaoermuizc
wrmpouzyicgea
mzpecogtuirayw
opriuamyewgcz
yuarigpoemcwz

tvfj
bvtj
nvftj

opjlskxcfgdrwmav
jmrhzacwdilpx
dhwjclxarqpm
bwcmpardljx

gtr
oajst
t
pwtg
utg

cuwpi
wcupi
cuiwp
pwuci
wpuci

icrlgewdmu
lhricgdwme
lergdciw
kwclifzredg

rnpwzhlqmkafov
rmnfzaldqokhv
hnrfakqvomzl
okvrhzqlmadfn

bwxpgnrovqs
vagbromxwjs
kxfsyb

nakv
nkva

bzkg
vgkz
rkgl

oklyx
kylox

ibw
wib
iwb
izubwxv
iwb

zikvprafh
pnajkvzif
vmiaxbkptzlf

mbouarxetzqcfg
hmojusvzelgnad
zigdupoylmwae

fsjyboa
pvhzlwkima
djrngxuae

ozry
rzoy
yozr

suydqovzgel
ulke
bluwe

uiykabnpgdxhlmoz
enhigdubzkopayml
psiagkznbmchdoyul
ukinspbamdgoyhlz
opnjmrkyughzbalid

nahxju
pxhnjua
hjnxlua
jxnakuh
uaxjhn

teqaxpfjkiovg
gtfpijeqva
gfqepivajt
pavegfiqjt

kglixrmouhyjbfvt
rkmlwixycujhtfgzb
frpasbtmugyhldijxk
rletbqjmfuhgixky
mwugybtjhokfxvnril

qrtpdcvhnoljbi
gsdphvmotljb
jvbpkewotl
lvjmnuozptb

zrxesgvquayc
syczgvqxreau
xlaeumyqcszvg

ojfgyctiksprhavmxeb
yvcsjobgetrxkpm
spjorevcqkgytxbm
gscojxrpbvdtlmkyen

otaibjyzxceu
xzceiyubojta
zbjxaieycout
odubiyxtacezj
ugowzxitacyejb

pfqwxeumsy
fyupexw

lnmvxqswzh
npstbrhcx
tmhazxndsg
uhnsrx
yjxnhoksie

xmrzgnis
imnorzs
snrmzi
qitspdrmzn

ws
ws
s
tqs

ndo
w
wl

moazp
pjz
zpj
jzp
pz

hwgdsjvkyteo
wtqzdjoy

ntzbhs
zsnhbx
hbsnz

kqztidpsmboyung
phymuiozr
xaoumiyhzp

kejuifmox
mfikxuejo
jifxueokm
iejmkoufx
ixfkemjou

auw
gudkr

sgenlwuohcb
ghekwucxnq
xncujhweg
geuqxncwh
grewnhcu

lomvbqwzrsgfeiajhntdku
vwzytogdmhkinecafjlxprsuq

pgleaswzbd
zaswfkdhp
apszwd
wsapydz
atdpzsw

wxhonybje
ojnwyhexb
bejxhnywo

olsux
zxou
oux
toxum
xuo

gxaebkqydnjzthirmcfpow
gtxiwdykrzmqohejcfabpn
xfaorpbgywzdncqthkemji

eglacoibktsdhumnyx
ukfxoetsbcwmqjigah
sbvughkyocditlmaex

tsumebadoq
oeqtusbad
piuohxndabqtrs

oty
yo
yo
oy

zw
tz
zsyuk

bpruyqoen
qykbfrzpeo
yeqpbor
nreyqpob
pyrbqwego

myrhzftueikx
fvdetmlxpcwsibhguk
ahnijxufoketmq

gvxfsulkyj
oknycdfrelw
flky
lfkgyx

dtgsf
tgfd

rsdag
adgrsf
fargsd
rjagdlms
gdrsa

ehurysjqofmtk
ytrfmuokesj
yvjfraemitksnuo
ueoyksjtmrf
esxkmwopgfycjlrdbtuz

hl
zfo

ieduqnyk

gpjisdyezo
kynwfce
vykerc

wh
wh
h
lkho

i
xhl
x

utzexphayjw
jyzwuethapx
thpueazwjyx

rk
kdr

oquelchwfivxakjmrpyzd
mjavklucigqwoyxezrpdhf
xzcuohkplafmwjdivqyer

uy
yu
yu
yu

wnkdo
cpkogadyvqtr
fdokh

mxgktesjocbl
hetucq
ypizcret
evctaz
qtce

zlidyjfbhopmxstcnrk
epqbhldkyzsjnfaoi
lkbnjisydhpqzof

eiagoyskthn
hgxtaivrmyplukobz
gyokihwat
gafytkihco

utxdvi
duvixt
xituvd
uidtxv

oxeyucapbnk
wtxmklujney
fxesykubhrzgona
uefycnxrvk

qpjnoavemkgxfuydlr
rwqucktobjelyd
dqrcuosyekzlhjt

jvaecytfpmxrdq
safuytleohkxbdvcipz

oizutcswja
uzwcti
wcuzit
tzwiudc

waphtlmdxzckqirb
mekftdrwzhjqxsplcb
tzkqdplmhuvy
hxzcrtkpqflobmd

glrfzsdbu
rfgdlubs
frwconquxylbsagdh
tgbfslrdu

dulbtwyp
fgct
trhkxa
nejhstv

zjgdsavc
dvgsacjz
sacgdzvj

fjsgwkziy
bwgitfk
rhkdpiwg

jfygdqpchxneb
jpwxzsbn
mrajoptnlvbxu
mxpbkwnji

th
fht
th
ht

kijvchy
aivjkhcy

fsqtcplo
tlcosfp
slocfpt
tpflsoc

gkc
gqck
kgc
cgk
xckg

swqxzdtmfplhibyjrevu
izhfjltywpmrqbevdsxu
evtxzpflqrjsdbhmwuyi

kdmbvqcg
pqckvdmb

witrzdagcbyux
irxgyuazwbdtc
gazbrywcetdxui
axinyzgrcdbutw
trbagmluciwkdxyz

uwbhvdy
wuvhcy

ygjqzpdrtsi
psqrtaidjgy
kmsghxlqnidtjp

cprkdbafqlwuihgvys
yubzxwmvogderf

xabnqejdtcw
dqtfejnwbmhxac
dwnbcjqtexa
wvabnxqyjetdc

pzo
zmnr

v
v
v
v
u

lht
qlth
hlt

lx
xl
lx
lx

eazpcoihwxmtudsyknrq
qldaiztcpoeynskwhmur
cobzyspahgrkinutdmweq

qpjm
elqujm
jqm
jmpq
mjq

oltnpgsmhbqwzexvikudyar
zyxqhatrgsenwlbokdipvm
eshotqirdnxbyklvwmgzpa
zeaqwofdpvxytrikhslmgbn
alkrqdxyeswmgnvzbhtopi

wzbhmvrtiq
wtimqvzb
ifcobmgwznvq

fgwtjydp
gjtwpdyf
pyjtdfwg
ftwypgjd

qmsfcxwdopnj
floqiwdmx
wxohimlfbdv
xakwymterdozgu

vrlq
ulhdwsmr
hrufl

gohrfpw
brzdtl

nhso
hn
nh
chn
hnd

myzkfxprtegohl
epntmxyoglr
tyqgiloxnperm
dgoewlrabcytxmpjs
urlyoxmpeqgvt

aiewv
wrativ

tglwzqhrjexkf
fuazgyqkvxrj

priylwgbfn
gmlbpiwfn
qdbginlpafsw
rinblpfwg
niwplbgf

zngjkchylqi
yfilnjschgzeq

wvmbrui
wxg
kwjg

ljvueoishfzabyw
ruwkeyzigsljaof
jyiwnzleafotsu

mcxv
jmwg
ktsnm
toim
mulyfrze

ku
ku
kuvi

ulotnbfrqcadkmjivpxgeshy
qcegdpwszryvjnuxmbohka

rfikmej
ctagoqzldvhnxpwuj

xpjwiftdynkcz
dxvcqtn

nelkupxgrmtijasqbv
qvilfbksnjgtepruo

x
y
d

qnzorg
rqzg
grzq
rgzq
gzrq

wqmofz
tlm
ml
mp

bfszturqkoxymjh
hkfuoqrzemstxyab

xevanum
efvmnax

bouykivwld
mbrnfczq

upvexa
aexvupsy

c
c
c
c
c

h
t
t
t

jati
tiaj
tiaj
tija
dptjia

vksjnyti
bvlksta
tmxvzpsc

ksqwt
stmqkw
qskwt

xcupr
iue
uwt

mznesjqwdu
eudhitwm

jmslovq
jsdcvgb
imsvj

oiva
izo
ig
crhi
gizj

wlecpsqrdh
rdextqhwpc
prdnhcaeqvw
rwdhpeqci
qurwjfhdlpec

tkaoh
xjecrywq

xeni
gvt
eft
pomsjacq

cxv
q
t
u
r

qw
wfq

oabsdwtgvqiuphnfexjlzyr
ardwyhflepinsqvbuzxgj
rswgxjdeyiphzvfulqncab
ywxvruidnsazlpfhqbejg
dfyvncgsiaezrhlxwbpjqu

jeklahmztuxnvqgc
jlhmekvugtqcnazx
hamkqunjztglvecx
muckejgalvtqzhnx
zkelhjncqaumvxgt

bwikegxcfoysruqvh
htpucnivmjzlad

qntrsyigzmha
aqtspyoxi
bwuvsyjeadiqkt

sfyamuxco
jdqfykzigv

plbctxfsagrdmovyz
oyhaesxcgznlmbpwvrt
pzdibfsocrvtlamxgy

mkvdbpt
dkvbtsp
xbkptwhd

pgldyjsqunafzit
olbzkdscvymhw
sybmdzlxore

pujqcnoeisagyv
qjcevnigaypuos
ceunsjqloaimvygp
niecoypusavgjq
puqacjoveisgyn

ilhxmtzjs
jsitmhlx
sjltiexh
lxhtsji

aiforvklhzq
zivlh
lgzhiv
lixjvhz
ihzcvl

fsztenwbpuqoai
cpvkthwdlrjuy
jwluyptg

qdjgnkzsputbvhlyoicw
rjipmyqnfwukstcoxzghblv
ucjyndisqgwvpkolbthz
nbjsizouwgcvplthykq

bzuyelgj
ubeljgyz
gzjbylue
zljgyeub
byjgluze

quk
ukq
upqfk
ugqskz
usrgkq

ftajvlypimzxshdcqnkwure
dnclmiyjrpzxeatskhwufvq
dpxkfzuevlatsijnrmhwycq
qnjvmukyciwzxpfdahlrste
fmzcxnaerptujisqhklywvd

krty
pths
zcotin
uyzt
tqladvbejgw

kcyfjpzre
fknbmoajc

fwzliqbamsg
biqamolzswyjfg
zslamfgwqbi
lxaqtvnhsfmpbcgzweui
afislomgzdbwq

vroeixdqfcwszaukygjlhp
wrmzvklhgoyxdciaejqfpsu
cqghksdzuwjvrflxpaoiye
dkxwcrpszagifyjlqhoeuv
vqkoywerdhgusaljzpfcix

nfcuoishtemrqyxjv
clrnxheqvoiuytfmsj

tkrqbu
ubrtqk
rukbqt
kqutrb
gbutkqr

xie
ixfe
eaknmyi

mjlreiaczpfbs
ibkehz
bezwxio
izthqbgue

cxegof
qrotsf

zslba
lbzsa
lszab
lebdsza
wbzsla

pnrdfmhqgbyc
bprgnvhyd
nhpdzeuaiojsyxrgtb

noeytqbsxfrl
obfntxlyresq
exybsrtfqnol

iwyg
ygiw

fcha
wma
zhanpwe
lzfaneck
bjuxogiavqt

pbjwavkdhczy
baywzkqjvce
vsjygktbczwa
vwzijyblcaxkmou

ryl
rxq
akcvpwr
lr

oqzty
yitqozg
zqoyt
qyzto

hugtzim
ingzchuyd
pkhuzsljxi

jx
xi
x
x
x

ofjhxmvksergiwybtcu
tolphrazkdmnxvjqbgwfu

fxchrgezya
egyavxfzhu
qazgfehxcy
yizpxgfhae
yefoxgrzha

fdeycphozusnrmlqxbgkatij
ibcljzfekypxraosntmdhg
rclgbmydkifnzhtjsxpeoa
ackshxdjemipfrgyznlotb

wumlxodgzvq
xrzkoqgmludvw
qzulvoxwmg
wugolamjqisyvx

jizxyhqgrnawmpueo
pasuqmtjnexolvr

xkguqypbe
osgkvxueib
nxsgekoub
gekvdxub

kngxpdyotlzfejvswcm
qplsjgtownxahbdrkfu

zjqeomhnt
tojeqhmnz
mtjqozhne
ejozmqhnt

syzqrhiwfp
hmqewc
vbhsqfn
tgaxkhqlo

fyhucdtvsk
kfhcvudsty
stbnyhuigkdjfc
tfycshvduk

rbhqwkjdvmpxageitnoflzy
xkthmoywqeidjplagszvbrfn

ktpfmlvsw
mvsklwtpf
wfptvklsm

rnlvdy
nxrcl

elwycpbnf
ncywf
wcyfn
fvcnwy
fywcn

bckpqzdwosyfvnut
oxpvukncbdwfzqtys
fzwpdtvybnscoqku

cbmrsxdipyfnvjo
mnpabkgqslufwx

kywscxvhq
vruiyhsezt
fjgnmy

qbjdkgltunyfaxsp
psblakjyedthnu
punsydztlkcjba

bphcoy
hbpoyu
bkopyq
atilojrpmby
pbyou

ibluxzvfswnghc
gwsfplu
uglsfw
lusgfw

sjlubyimoegkpftdavhcrqw
amouhdfilybrjgetpwq

orawjpscyfdnelztqbh
sawekclfpnbqzodth

ntjuvmwpycf
szjagiteydvnmplfwc
myrhnvxwpcfjt

rdosc
rdosc
dsrco
rodezcst

ncugi
nbgwup
ugn
nug

n
n
nl
n
n

ntflyovsdhmkcgp
kantmvyrpdhglio
tnkvpidloymbuhg
ohtvdypnmzwkgl

nxqs
nqx

jp
jp
jp

ejskx
oryamnsvzg
hdjs
uwtsh
sh

bpcugtovs
gweokzqstjvlp
gtduvshopria

uthdirywmvgbxe
zugeithvrynm
yoivghmuqtr
typsgmlfhrivuk
erdvuimhtyg

eydpbq
dbyeq
yebqd
webdqy
debqljtyv

munbwc
lnvu
nu
nu
ynru

gftdzau
gufszr

fyxzhbwnuptil
sygzkulwpqfinht
tfwuihlcypbdnez
pnhyzmulwfit

acryonbgetshwjfxzml
ozhmrcfalxwytbsugej
ehybxrfjcqtsozawgml

z
nfej

mhvxlkbtuyo
hfxqabklvygmc
ykbmvohxlws
ekbxvrhyml
yobvuwhlekxm

ambpsyie
bcimpyase
ebispmay

lydzmsgoqijxkthcewpbrn
ynlpjgqrztobhmkedxsiw
jpwrluxgbismezdnyhqtko
vrdkxhnjgeysbtofqmwzlpi

mvkyralfjqtu
iazljont
tzdclaje
ltgjza

nsizhmgdoewlvx
lwghmdxzovnsie
doghnvsxewmlzi
lnswzoivdmhgex

cadutlrvyk
xaouyv
vygua

z
w
n
n
n

xjlvfhcgbqyozt
zcyqbtgvljeofh
yczjfqouvdtgkhbl
gbvzflyjhcqot
ftbcoryzgqvhjel

fnkspvetum
edmstgnqkjvx
puesnmvkita

ytrbqlwcvusz
qmjcl
qcxl
hxgclq

ldg
d
d

sc
cs
cs
sc
syc

axpdoftgkme
adleukosgxfmry
kgfeonazbdmx

muxqr
rmqxu
rxmqu
ruvxmq

qhidvckgolepxsuj
zfvinabmcewpkgt

pcvmxbdo
wyodpmcx
ojgrdxcpm

jimg
mljsi
mji
ijms
imhzwj

jfkbp
zndqof

ed
tdef
capdkyize
etdf
edtqv

vhm
hmv
hmv
hvmt

vylapqueifs
vpyqilsfaeu
paqefisuyvl
svlepfuqyia
eufpvialqys

jowmpltbdxyrvu
mudxhrcbfzjqslwptk
dbrtulxpjgywm
uwpmtjndlbrx

ilnxbpwdrvuokfjgtzec
inxbtyczgfjwdlveour
ohznidtmxuawbcgvlerjf

q
q

xmjs
smwj
jsm

cyfp
soxgrjm
pu
kfhe
tw

rhuey
uyhrge
erhyu

d
d
tmd
d

muciswt
stmic

ldxnfy
nqler
nlkb
ln
lbn

eyqhbgiwfkjlnx
wtekhamon
zcseurhpnk

xumhwodpjfgalqns
gozkaxbrwvc

kioucnzelsy
foyuvzceiknls
ksenoulzycmi

nefyugdromqbiksz
isomrdufqbkgzyne
pesmfngbrkudioyqz
gsmtfeodynqkubrz

xskygfdipzwchrlvatb
dhgawjcpirkmvtflzbxys
izrvshfbdwlapygxctk

mb
qzmayl
fmt
tmh

csjthr
tflbks
bstfpda

qojyvbtusn
ovsxbhqytuj
weojbisuqytv

aepz
eapzb
apdezm

syoeagjvfl
fejtvnmqxrphzlbc
fgviejsukld

ylbqv
qlvby
vyqbl
blvyuheq
qyblvz

evusaopzdy
zvypducloea
udvozyepac
adystoeupzbc
gzmpdaeqwukyo

fglqnbtpra
robpaegfktnq
mntqfaiprklob
prjfybutdwaqncsh

q
y

rcz
zrc
zrc
czrf

rh
rh
rh
hr

aynwkrpfuvhcblqtzixgeojsm
mvtpirakxuhwfyjscbqgnoezl
mlcuqzoihdgrxfvyswtbaejpkn
rpialswqmbnvehcyxjfuogztk
amkhqocevbwxlifsyrntzgupj

rljduyhgnzwkp
kuydljrnpgwzh
uykgjwrdplnhz
ngdwzylhpjurk

wexrly
yxqlrhemw
rywxle

t
e

pxhgaqjv
rnjxltuqh
myqfwekcsdix

gwdfvsolhup
vlgdwuspohf
fdrvuwopslgh

zhsrfjbcndwqyvupgakemoxlti
xhtoyfnlwpzuevgdmbjircakqs

ldgebj
jleg
jugle
glje
egjlu

jlnzs
nj
jn

jfhdwsg
ltkpanyihejxsg
hsjrgmc
gmsfoqhwjc

evjngcfizyuoslpb
ozbsiefngjvpcuyl

pjbred
jdtbkp
awdbjko
dbj
vmdcbjhl

iudzrx
agykxzu
xukzpa

ou
huo

l
l
lb
l
l

hfpw
wphf
hpwf
lfpwhc

wajmh
tqfpcselurxi
kbz
ywg
dkz

sgw
cyezglipksuh

oexibpzgr
pixobge
xvucyptmqib
bixozp

va
o
wnjky

zevpulnqaikdmwsyotcr
dzvkjeinuslfrchqmgyw
vezxklwdqynursmcfi

id
dvi
sdiz
ids
idq

bmpxyk
cnykjbmexo
xydmatbki
dxbymk
myxbk

atzibcu
ticuazb
icazbtu

nypbqmhuc
sjqzoetl

dxumvboftrwzihclgqeyk
mhrfecdvzgikxujyqtpwbaol
nkobczmqytrlefviuwhxdg
vgcelwryqhznbtfxkmiduo

fzxyjegvadrltb
rgehucmqpn

nfrx
ufxkverj

haqu
qk

fgchqktrynjbwduia
umnljcwifthzqpovd
xwenjtqihdrucsf

zkjmoyh
oyhmzkj

xdsoglwprq
xlmwoqg
luqxwyogm

yp
bgiw
l

liefqvj
jefiqlv
efvljiqr

axnpoecuwibslgd
xeougsnz
smxgueony
qexumgzonsh

wua
adwiu

n
nk
n
n

maijgrtsyn
sjytikamrgc

cwnetku
gilvzhsa

hywvukqdmjiezrbtnplacg
ejinbtdzwgmkyqhrlfcap
uimwlzrnkbqgjvtacyedhp

grud
dxuerg
urdgh
diugr
iurdg

tfwiqjnmbue
puylasdgzocxh

ysghmdqol
omlqhgd
imqohjdxrgl

fkayurzxndqieobvht
qmrnbfkahieowduvt
cefarktbvhqiound

qptdrbmzgk
dmbq
lbfcq

tjxkogms
dcphwbfulxenrmzi

ohreptydvgsiwnubkz
vbgkoshpdluzeyirtn
xiqskhnadmjtgyvbrpeuoz
oknhrzvgbepysutdi
ynegfoubrdctsihlpzkv

zrn
rzn
rnz
nzr
ndrz

hpgliyawdbsrxfkqjen
rsdielyjxqakphwbgn

qvcjphegszrt
tjcaermgsvz
dgcjfuapeozhsn
gwexszycjkibl

cmsjwrbudoi
ezqwslombvj

glw
elo
mrxkctaqu
hnsjf
jwvbi

kotwglnpf
pugtlxn
npltg

gdxpkcyuqezlonsfam
wjpsozehatqyk
izykpvoqejas

xbjouepi
samvuxp
xvprzu

rq
rq
rq
qr

ocvehwzqfurayknlix
uxekyhclarqwonvifz
wdruxcqnkohfayezliv
oqrnxawlhycuziekfv

xpcgsrelqw
mwdrceplsqx
pehrjxcswlq
seluwdrqcpx
qwpeucsxrl

d
u

epijobawgtdqrylszxnf
rwpxfzbeyosadntqjg
fbxwyrcepozajnsdugtk

dtecfku
eiutfkr
tefuk
fteku
lktuef

dmrwnhbq
oimnyltvqphze
qchkmsajn

nfw
nwf
wnf
pnfwq
wnfe

brw
rbw
wbr
brw
bwr

pyuxqzbcnmrdwjkgsoe
jbudewcygrsqxtpmozn
gzsibnfydwrcjvmxkuopeq
whnoypqjrcgulszmbdax

pdfzoknvgbr
fgokwnzebdvrp
borzfpvnkglh
krfgplvznob
pgvmnzbcfkroyjs

jgszrlwvi
wvonhpy
dnfmtwva
kvqdtyw

xrzhqlgpevtcwm
ehglzctpxqrmwjavu
clmhowtkgpiyfqrnbvxsez
vpzhmrxqewdgtlc

waztysmcegnurkvjqdp
vosdabjykpmgzcnuwr

bwutrjc
urbjwt
jurztwyb
utbjrsw
zbwutjr

zeckigrwv
zswgrcivke
ceywkizvgr
kziyvtwcge
gzfanbvwxmceidkp

n
n
n
n
n

mzwbnksrt
tomrwnkzs
mknszowrt
ktrnmswzv
mtwnrszk

y
y
y
y
y

rmbditwshcfkpjnozavyx
dyftmzojakhrpcwxsvnbe

avdbct
dvatb
amdntlovb
vadbtc
bavtd

ruyvefoqiaslcdkm
iaouvsmyefkcdrlq
uqoescaifkbvdrmyl

dkvxyjsbwhqac
pcjbqyaeuvgfostx
yrdxkqjacsbvm

ugepzw
derzibs
jyokqvmal
fhc

qupyrj
ibmzegkto

xksviqnyurgw
vkbnurxlyqg

opgw
smbvpg
bpds
gjp
fpta

xtlncsiwjhbygrdoumzkqvaf
olsxbuwigdzmhvtyrajnqckf
lajzbuqswcnvhkdfomxtiyrg

pakwbfxuq
wxpafkuqb
bkqpufxaw
axuwqkfbp
uxwbfpkaq

eqsgztjkimn
nqjzyst

cn
nc
nc
cn
cn

rv
rv

pbwsuy
jshcqt

vbjkzyprhm
jkmbrezygvhup
rhjvmbpyzk

ochfjrqmy
qrfocyhmj

ksrx
hcrbzu
rdc
jrcp

soixrchpvek
qbtdocpixwalfvnkm

zmtlj
zlpyjtm
rthxldmjaniz
zluptjm

rcyshqp
jbdnpe
zgp
pnjtz

use crate::common::AdventOfCodeDay;

use std::collections::HashSet;
use regex::Regex;

#[derive(Debug)]
struct DeclForm {
    answers: HashSet<char>,
}

#[derive(Debug)]
struct Group {
    forms: Vec<DeclForm>,
}

#[derive(Debug)]
pub struct Day06 {
    groups: Vec<Group>,
}

fn parse_form(line: &str) -> DeclForm {
    DeclForm {
        answers: line.chars().collect(),
    }
}

fn parse_group(lines: &str) -> Group {
    Group {
        forms: lines.lines().map(parse_form).collect(),
    }
}

impl DeclForm {
    fn contains(&self, c: char) -> bool {
        self.answers.contains(&c)
    } 
}

impl Group {
    pub fn all_questions_any_yes(&self) -> Vec<char> {
        self.forms.iter().map(|p| p.answers.iter().collect::<Vec<&char>>()).flatten().collect::<HashSet<&char>>().iter().map(|p| **p).collect()
    }

    pub fn all_questions_all_yes(&self) -> Vec<char> {
        self.forms[0].answers.iter().filter(|p| self.forms.iter().all(|f| f.contains(**p))).map(|p| *p).collect()
    }
}

impl Day06 {
    pub fn new() -> Self {
        let input_bytes = include_bytes!("../res/06_input.txt");
        let input_str = String::from_utf8_lossy(input_bytes);
        
        
        let rex_lines = Regex::new(r"(\r?\n){2}").unwrap();

        let data = rex_lines.split(&input_str.to_owned())
                        .map(parse_group)
                        .collect::<Vec<Group>>();

        Self {
            groups: data,    
        }
    }
}

impl AdventOfCodeDay for Day06 {

    fn task_1(&self) -> String {
        if is_verbose!() {
            for r in &self.groups {
                verboseln!("{} {:?}", r.all_questions_any_yes().len(), r.all_questions_any_yes())
            }
        }
        return self.groups.iter().map(|p| p.all_questions_any_yes().len()).sum::<usize>().to_string();
    }

    fn task_2(&self) -> String  {
        return self.groups.iter().map(|p| p.all_questions_all_yes().len()).sum::<usize>().to_string();
    }
}
Result Part 1: 6683
Result Part 2: 3122


made with vanilla PHP and MySQL, no frameworks, no bootstrap, no unnecessary* javascript