1
0

feat: solve day 8 part 1

This commit is contained in:
Rokas Puzonas 2021-12-09 02:00:23 +02:00
parent 7732549963
commit df6062873b
3 changed files with 266 additions and 0 deletions

200
input/8.txt Normal file
View File

@ -0,0 +1,200 @@
cdafg dage fgdaec cdbfgae cge gcbdfa fdceb gfceab ge ecfgd | eg eg dfecag ge
efgcabd edacgf gfaec deg dg decga dcfg dbgafe bfgcae abced | deg baced fegac aefbcg
egacf dfbeg dec efcgd cfad cfagde fabcgde dc agbecf bgdeac | gcadef eacgbf egdfb bgdfe
dc cgefb cdf bdfgc adbc gafdec cbagfd gfbad dbcagfe gbedaf | cd cd agfbd bdac
dcbafg gadeb faegb cfbga ef gfe feca aegfbc cebgdf dfabceg | faec ceaf bcedgaf cfbga
bcf adbcef cbgdfe dbceag gcdbe dcafg egadcbf fb dgfcb gebf | cbgedf cbfdae aegbcd bf
dfge dg fbgce ecgfdb fcabdg bafgec cdg cbdae gecbd ecgdabf | eafcgbd gd cfgbde cdg
fadbg badfe faebcd gab ebfgad bfceag gfbcd gade adcebfg ag | gbfdea aedg becfad aedfbcg
gcfbd dga bfdcga gafdbec dcafg defac ag adbfeg acbg bfdecg | dbgeaf ga dagfeb fagdc
efdab cgadf cbafd fgbcda ebgfdc cfb bc gcba cefgad gfabcde | cagb fcdage bc dacfgeb
acgfe gcedbf fge dbfacg bgcfa fcbaegd ebga eg feacd egabfc | geab fgabc cfaegb egfcba
cef egcbd fbage cf bacf fecgba fbadegc fgdeab fcbge daegcf | dfaegc bedgc ecbdg becgf
acdb bdegc fgced dgb fbdgace agefcb cegdab dbgafe bd baegc | fedabg egcdba bcafeg fdageb
adbfce bfgc dfcebg efbdg cbefdga bdcge cb afgbde gceda cbd | ecgad egfdab dbc fgcb
dafgbe ecafg edcbfa fdcg cef fgade cf gecab gdacebf cedfag | bdcefag gfdea eacgb cf
acedgf becdgfa fgcae fdgac fdcgb aged gcfeba ebfdca ad adc | begfadc dfgac efagc fgcade
gefbd beafgc dabge fgad ag bdcegf agfebd gba acdeb dgacebf | ebfgda egdab febgd adgf
cdage gcebfda dea bceag de bfcdae egbd egbdac gebafc cadfg | ebdacfg agcbe adbcegf degacb
becf fcd cabdg gefdab dbgcf ebcgfd cf bgdfe edfcag egafdcb | gdcfbe gefbd eagfcd gbcfd
ec dagcf debag eagdc cfabed eca begc bfeadg dfcbaeg bgeacd | dcagf decgba eac cefabd
gace egadbfc bfecgd dce beadf decfa gcfdab fcdaeg ec afgdc | afecdg badfcg cfaedg adegfc
cfbge ac cea fdeab adfbgce fabceg dgfbce abcef acgb afecdg | bagc cfebg fbaec eca
gfdcba bcf ecfdg bc baefgd efbgac caeb aegfb cebfg badfegc | cfb cfb cfdge cbf
acg cagbdfe ca fgcadb agcebf cegfd acfgd dacb bdfga feadgb | edfgba fegdba gabfce bfegda
eabgfc gfeac dgaeb ecgdfba cba eabgc dfaegc cb cfgb cdbeaf | agfec ecfdga aegbc bedga
defgac eabdcf be faedg beag bgdfe gdebfa ebf bgcfd bgdceaf | dfgcb eb fdcaeg ebf
db cfdbaeg baecgd dfbega bdgaf afebg febd adfcg aebgfc bdg | fbaegc fbgae bfde abfdg
defbg cbdfeg dcbegaf cbdf cfe begca aegcfd ecgbf fc agdebf | bgfaed defagc efdgb cdfb
ecdafb dbf bgdea abcf fdaegc dabfe fgecbd fb deafc fdacbeg | afdbce facb bf fb
fa edfabg bfacd gcefdba fba agfc cfedb fagcdb agdbce adbcg | efcdb edgbaf cadgbf gcfa
cfb gcfbea bacgfde bc geadfb badc bedfa edbfc ebadcf gdfce | gbfdae fcbedag gaefcb cebdf
cfd gdeac ecbfagd cagdf fagcbd dafb egcfab bfgcde fagbc fd | fdba cagdfbe dafb dcf
fcageb fa gfa dbfa begdfc dcega gdbfe eafcdbg fdaebg afged | faedg gfa afegcb eabcdgf
feabc gf agdbe gedbaf fgbd gfbea becagd fge gadcfe cdeagfb | fgabed gf afcdeg aebdgc
dfebc gedfcb bcgfd fde dgbe afcdge dcgfab ed befca fbcaedg | bfcged fde febca dafbgc
ebafcd acbd cdebfg ead ecdbgaf edacfg efbag da fdebc fedab | cgbeadf bacd bcedfg gbcefd
beadgc bd gcfba adgce cfedgab bgd cgfdae agcbd gadbfe bdec | gebfad dbegfa cbafg dgfabe
fdecagb bdafce gbcfde egcbd ea eadg cbgae gbceda agcfb aec | cfabg cgfba cgdabfe cafgb
ca fegabc bdac gecdfb feabcd cea eafgd aefdc dgbaefc edcfb | fbdgec aec cbad adbc
baegfdc egb fcage bfcged bfdea gafecd gbac bg caegbf fegab | cfadebg bcgdfe gcbefd bgefa
fdabge faedcbg dfbea gfcade dfe de adbgfc egdb eafbc badfg | dabgf fcagedb gdabef de
bagcdfe dfaceb egdafb facegd cedbg ga dga bgaed fbag bdfea | bedcg afbged dfbea dcbeaf
cdbef caebf defabgc ecfbag cd dfc aced dbegf fcdbae bdgfac | ecgbfa cd dc ecfagb
facbdg dfgacbe bfcgd bcgedf bgead dec gfdeac fecb egbcd ce | gdbaefc bagcfed bcgdfea cdgbef
abcef ebfdc dfagcb dcbgef ba daeb ceagf dcaebfg faecbd fab | dabfce abf fgdaecb dfbce
cbe abecgf be gbacdf dacfebg eabcf aegcdb gabfc gfbe fdeac | ebcaf cdbfeag fcdea egfb
gfad degab fcgdbe aeg bfedg abdgfe gefacbd ga badce fagceb | cfbged efgcab bfdeag fdbeag
fgadbce edbag dgbcf dabfg fa fdaceg bacedg faeb bfadeg gaf | fa abfe bfdgae gdafcbe
afde cfadbg gcdbe bfdecag ea efbacg abe cfbda debac dacfbe | fcbega ebadc eba cafdeb
cefgad bdcef acdbfe edbgfc dae beaf bdacefg ea becda bgcda | gdacef adbefc bcgad dceafb
dfbaecg eagfd cf acdf bcgea bcfdge efc dacfge efacg gbadfe | fc fce fecdbg caefgd
afec daebgf dfgcab fcgeabd gef afcgb dcgbe ef gaecbf fecgb | fe cgfab debgfa fgceab
cgafde afbgdce bgafc gabcfd bgdf badgc gf aecdgb ecabf gfc | acgfb gfdb cagdef fcg
fdgec bgcad bfec gbefdc dbf gfdcea fcbgaed bf bfgdea gfdcb | ebcf dbcgf dbf bfcgd
dfceb cdaf bdfage afebc bgfdec fa gbcfdae fea gbeca faecbd | fcgebd fbgaed afdc fa
fgcaeb fcag fa bdace efbcg gdfbaec fab dfgbec abfce fabdge | gcedbf cefgdb ebcdgf efdgba
afegdc fegdbc gfeab cdfb dcegba db bde degfc bafcedg dgfeb | gabcefd cgdbfe bde afgbe
dg gbd adgfcb cfeagb bcfag bcgfd gdaf cbfed gcfaedb ecabdg | dfbgc dg cdfbe dbgfc
cebgfa gcadfeb afcdeb dagfb facdg adbfge bdf db egdb ebfag | dbgfea db bgdefca dcfabe
adbf fgd bcegadf cgfead egbfd bgeda bdceag bgfce fd aegbdf | gedabcf fgbde cbegf cdfgea
ga cgbfd decba gaecfb dfbcga cbdgfe cbdegfa fgad agcbd gab | dagf egfcab bgcda cdfbag
egbfa geca fabcg edfba fge fdcagb cgebfa dcefgb bgdface eg | egafb fabeg fbade aefbg
egcad fadbge fbgd faebg acdbfe edabg bafcgde dba db fecbag | dcgae cbeagdf dacbfe db
ad dcbag cegdabf cgbea feacgd adeb debcga acd agbcef dfbcg | dagcb aegbc cad dgfcb
cebad cfadgbe ecd gdcbae cage cgdbef ce cgdba gcafdb adebf | adecb cfgdab cedbgf daecb
fagceb cbdef cabgfd gadbc ae dfcgeba gcebad bae aegd abdce | abe bae bae gead
efgcab eagdf de ead bfde cdgabfe ebfdag fbeag agedbc gfdac | fcgad eda dgfac eda
gfbeadc cgeafb gdecf bcedgf dfgca cdagef bgafd afc ca cdae | fecgad dfgce cfebga gdfba
fc egfbcda dfc degfca fgdbc dafbg febc dcebg cebgfd ecbagd | eagdcf efcb agbfd bfecdga
db acegb fdbegac dgefa gfcdeb egadbc cdba bde geabd becfag | dbfeacg adcebg cgedab decfbga
ecg acfgde cedb dfecbg gcfdba ec cdbgf cfebg efdbcag fegba | ecbd aedcfg cgfbe gec
fgcadeb ecfagd egfda cd cdf edac fecdg fagdeb gfdbca gcefb | dfgea adgebf dbfgeca cfagbed
cfgedb fgdba cgdef edgfa ea fbaegc age decgaf aced gbedafc | aecdgf dfbag aced dfecbg
de agebc bcdgf fagbec adbegc cbged daec gdefacb deb gdfeba | gdbace aebgc begfad adcbfeg
fdeg cfbgda dcaef dceab gdefac dcf cgafe begdcfa cfeabg df | fcd gdabfc bgefac egcaf
efgbd cgfbe gcb egabcdf debfag cg cgdbfa bceaf cdge degfcb | bfegad cgb gebdfc decg
aefbd bfaec bdgcaf dgeb de fgceabd fgaedc egbdfa badgf fed | bgafde fbaed gdfab gbed
bcdea defagbc fdce cbfade fagbd egcfab cf adgebc cbf dfbca | gbadf dcef dcefab gbcfae
abdc cb bgc bacfeg fabgd cfdeg fcdbg gcdebfa dgaebf dgbfac | gbdcf fcbadg cbg ebagfd
bfgca gfbadce dbcag ecabf cfgead fcg gf edabcf fbge afgbce | bgcda cdgba gf bfcgaed
afgbde cfdgb afbcge gbfec ec cfe dgface gfbae fcagbed beca | cbgfd fdcbg gadcef cbdgf
bfdga gaed dbagfe cgdbef edfba bcaef de gbeadcf gdfacb bed | ed aegbfd adbfgce de
adcb ecgafd ba abf bfedca gdbfae edcaf bgaefdc fcbeg fbeca | efdcga ecgbf gcefb dbeafcg
ac bdecf bac daegb bdegca bcefga gacd febdgac abdgef badec | cgda cagd bgaefd dagefb
gcd ebcd cgfbade dabgfc gbdcfe fdcge gceabf dc gfead ebfcg | gfdbce baefcg dceb fcebg
ceg cfgae facbde ge gcfba bcdfega edacf fcgedb dage cdegfa | dafce ge cdfae fbdeca
decgf fadeg fgaced febda eag fagc ag bgadec fegbdc bafecdg | afdeb badfe aecfgd adefg
da bdeca fdgbce afdbegc efbac gacedb fbdcga acd cdegb gdea | gdea facbe cfeab bedca
ebagdc cdaefg cebfg fadg gd ecgfd dge afedc ebadcf dfbcage | eacdf dagf cgfbe ebfcg
fdbcea ag fag fegdba ecagfd bdgcf afecd afgdc cgae efgabdc | fdaebcg caeg cfgda dgfbc
ea cabgde acbgfe cefbgda acde edbcg aeb ebfgcd dfgab aebgd | cafbge dgfab cdgbe deca
acfd ebgfcad fecbgd dcgabe ca eagfc eac gefab gfdce cgfdae | cgaebd fcad geafc egdacf
fdecab bf fdcb egdaf cgadefb edacgb ceadb daebf afegbc efb | dfebca cedbaf ebfcga dfecab
badef fbedag daebcgf bgcfa dacgef cfadeb dac dcbaf dcbe cd | afcbd dbec cebdafg bacdf
fagedb acbge fceabg cegfb bagcde aecf cfbgd aegdcbf efb fe | bdfaeg fe febagc bceag
efagd dfacg fgcb dgc cefbad cgabde cadfgb dbafecg cdbaf gc | caebdf bcaedg afgde dfcga
egcbf gbdafe fd edf gfecd gcbdae aecdg fgdcea gacdbef cfad | cfbeg cedga fadc facd
bdfceg acd dfbce bfdag ac adcfb daefcb egadcf cbae edfabcg | dbeacf fadbg abecdf bedcf
bcf badcf ecdaf eadgbcf abgf defcbg bf ebgcda bcgda acbfdg | fcb decfa fcb facbgd
da cda adceg bead abgcfed ceagdb gcbed cfgae agdbfc dfbegc | fgdbec cdgfab gebadfc fgcae
gbaecf debfg dbaceg badc eagdb ab abfegdc dcgea cdefag bga | ab cedbafg afcged cgdae
dacfbge dafbc baegdc fagbde dacgb fbcg bdfcga fb abf fdace | acegdb ecfad badfc cadfgb
acbgf gadefb cd egcfad bedc cad cadbg cagbdfe gdeba bdgaec | gceafd gbfac egfabd dcbe
fdbgcae feacgd gcdfe cgdefb gabfe defgb dgb db caegdb dfcb | cgfde cdebga cgdaef gedcaf
ae gacbe facbge cbdefa eca acfdbg afbgc gecbd gcaebfd agfe | ebafgc fgae bcaeg ecgdb
bfdceg badecfg bgefda ba bfa cbda fcage cdeabf fbaec efbdc | bcda fba egacf efabgd
gbc bdgce gcbdefa geac cg bedca dfbcea dgcabe afdcgb gedbf | dfbcea fcdbea gc dfabec
becdf gaedcb cgedaf aegcf fagcdeb gfab gefabc cebfa bca ab | ab gaebfc dceagb fcbdaeg
eagbc acfdge db gfadc fdgb fbagcd dba dcagb gecfbad efbdac | fgbd cgdeaf cdgaebf eagcdf
ga eafg adbge gabdecf cbade bdgfea afgbcd gfbde gab cgedfb | gaef cabed fbgdae agb
efabc cdeaf dgcfa ecbafg ed dagfbe bfadec egdbfac cedb efd | efd bfeca bdcfae de
bagf fb cfeba gcbade cgaeb adfce befgcd cfb defabcg gcfaeb | daecgb bgeca egcab febdacg
dfceg gfcedb bdfea gb bfedg cgdb afgebcd fgdace cbfgea fbg | gb dcbg bedfa gfacbe
gecfab dacgf cfbgdae afdcbg afde cea gcebd fgecad gcdae ea | edacg ea ecafgd gacbef
ag afg bgcdef abfec begdf gadfbce bfgae egbafd egda gadcbf | gafdeb ga bafec dcgbafe
cgadf cegdbf egaf dga efcadbg dfcge ag cabdf eagfcd cegdba | bcafd gdcfbea cdbaf ag
dcbge fdgabc cegba aegfc gfebdc ecfdbga aedb cgebad ab bga | ba aebd bgaec cdbeg
cdg fgdb adfecb gdabfc cagfd fbadc febcdag cdebga geafc dg | gd deabfgc fbadgc fcbdae
debgac fceadb eg gbcfeda gfabde efgd gfbac feadb gbe baegf | baedf edgf cabdeg befdca
cf bgcfe cfg cdgabe cbdf dcfegba bgafe cdefga gbecd edbgcf | dbcf fcbeg cbdf eagbdc
cbefag gbe agec cbgfdea gdbfa facbed dcebgf eg eafbc ebafg | baefgc bdfeca eacdgbf egac
gfd bfgec dfeagbc fedgbc fd cdbf fbeagc efbdg ecgadf daegb | dgf dgf ebdcagf eagbd
fcedbg bcde be fgbecda bfe fadecg edgbaf gcdef becfg fbagc | efdcgb bfgead ecbd fcedg
fbdgae gefabdc bfgdca gbf fcabed cafbg bcdaf gcbd gb agfec | acgdfb abgfdc bfg fcaeg
cfbegad gdfcb bfgde bcdegf egcb bc adcfg gadbfe beafdc cbd | fgadc adecbf gdbefc gbdfe
abgcf ecabdgf dba acgdfb gfebd dfac adbgec da afgdb cbaefg | fbagd dbegf begdf defgb
bdecfag ef bcefda adgce feagbc gbef gfcae fcgab afe fdabcg | cgfeab cfgea bdefca afe
dg cbgeda bgdfa egfd dgb gebadfc febcda gcbaf deabf gaebdf | bdfgcae afgcb dgb bceadfg
cfagedb eacgd baecfd cbafd ef eaf bdfe fgbcad dface febacg | afe fea fdcaeb cedga
fdageb egbcf ec ceb dgcbf gfeba fegcab acef bgaecd cebadgf | bec dgafeb faebg fcbge
agecbfd fcd gbedac dbcfag dfacg df gbcda fcaeg febacd dfgb | dcf gcfea acegf gdabfc
dafebc gbfa agdfc fbcgad fgceadb cdbfg bf bfd adgfec bdcge | fb adbfce feacdbg gafdc
caebgd bgcf gabef bf agbec abfcged bgeacf ebf edfag cfdeba | gaebc fdega ecgba egdfa
deba eb bfe bfaedc ebfdc cgdfae gdcafbe cbeagf bgdcf dacfe | gefcab gbcaefd fbgcd bade
aefcbgd afcde cea aefcgd dgefba efagd ca cagf gcdabe edcfb | adfgbe fgead abfged afgde
cadge fbagec ag ebcdgfa dagf afedc age ecdabf cbdeg gcfdea | eag cafde ega gfacbe
cbgefda acd afgdeb dc fdgab dcbfae gdbc cdbgaf acfeg adcfg | fgdac efdgba dfcag efbgcad
cegad bfgcd baegfc facgd aebgdc af fag feda edafcg cgfbdae | af agdfc gbdafec gfcda
aecgdf ecgfb bfdea cfbaged dgbfce cdf gdcb dc bcdfe aegfbc | dcf gabcef ebcgf fdc
bcafe bfcdea febga ac cfa cdeagf dabc cfdaegb cfedb cfgebd | bedfc dbfgce dcfeb egfba
cgfedb afcb fdc fc bdgcea gacdb gedaf ceafbgd cfgda adcgbf | cgadb cafb dcf adfeg
ebcf def cgaedbf becad bagfd egdcab fgaecd ecfdba ef dfbae | eabfd becf adcgfe gbdfa
gcfabe gcabe dfgca beagdf fbg abfgc bfce bedcag fb fbcagde | bgcae bfce fb bgfeda
dca ebfdacg cgbd gabfde cgfad gadbcf cfeabd fgeac bgdaf cd | cdbg cad dac cd
ebfgadc efgbad bdfceg cbdfg gecb bfedc fgb gb dafcg fedbac | fbg fbg cgeb gebc
ecadfb fdgceba gdebac dea fegdc feagcb ebafc fadce da fabd | bfcega cbaedg cbdeagf bafec
dbf fdaceb cdgefa bf febgacd aefb fdbca cdefbg dcagb edcaf | bacdf dfacb cbfeda aegcdf
gdbef bae edbfcg bfcag agde gebaf gaebfdc cfdabe afdebg ae | defbag afdceb gebfa agbfed
edabf dgbcf bce afecgb degc dbfec bfgcaed ce bgdcef cdfbag | gedc cbfed dfbgc cdeg
bdcfga fag dgafc fg dacbf bdafec cfbg fabdgec eabdfg eagcd | debcaf eacdg geabfd gbefad
cgfda badfc ba gcfdba acfbdeg bcga ebfdag faegcd abd dcfbe | afcdbg acbg ecdfb bdfac
bcdae febgc egdbafc fd gcfd bdefc bcedgf fbdega fde fabegc | dfbgec efcabdg cfbge gdeafb
bfedacg agfdec deg gd decbf ebgcd eadgbc gbfeca bceag gbad | gd ceagb gd gdcafe
acbgd dbfceg cegfdab dbaegc aebcg ecb be dcbgaf egcfa eabd | adeb bec begcdf gfeac
gda debfa gdfe gd cfdgbae bdagec badgfe bgdaf cbdefa fcabg | geabdf abefgd dag ebdaf
febgcd cdaegf bf fabge edafbgc gfaedb baegc ebf fdage fabd | dgecaf badefg geafd dfeacg
adegfb cbgefda dcag agbfdc gbcfa gadfb bfecg ac acdfbe cba | bfgca facgb fgcba ecfdagb
adcf fbecdga dbeagf ac eca gefdac edcag cfbeag edgaf cgebd | dcfa cadfge adegc gcaed
acbdgf gaecfb ad cbdfaeg gebfa gcbed efda gad baegd afedbg | gbfea aegbd adg da
da abd dbgfc dgca gadbf bcgedaf dfbacg fbeadc bfecdg gabef | cedbagf dfcbg gbdacf gcbfd
agcdf cbfgd da dacb cagfe abgdfc aedfbg agd edcbgfa fegcdb | da ecfag aegbdf adgcbf
cd aegdb acfbe bgdc ebacd dbfgea feacdgb agfdce dce dbceag | acdegb gbdc gacdfe dcbg
abc deacbg aecf cgafb dcbgf cgfbae gbaef ca geabdf gcbafde | cgbfd fcea abfeg feca
eagcb edacgfb abfegd abedf aefdcb gfda dcbfge gbafe fg gfb | cbfade acdebf gdfceb bgf
dgcab aedgb gbdcfae acbe beg gebfdc gdbcfa fdage dceabg be | gcedab baegcd bdega beadg
gd dfcgea afdgeb cdfae befacd beagc ged daegc afebdcg cdfg | cdega dcefab gfaebd ebgac
gfcebad gfeca bdcae fbeg cbgafd bg dcagef gab gacbe fabgce | ecbad abg agecf bg
fegdc bdag gbedac dcfeba gfeabc ebfgdac gedac ga ceadb cag | fecbag ebdcaf bfcega aegdc
deabcf dcfa cd ebgfda ecabg aecbd cegfbad dbc cgfedb faebd | gdcbfe cbd befad dcebfg
gedcab bagdfe bf aecdf begf aefbd dbf eabdgcf bfdagc eagdb | fdbea fb cedfa gafdbe
cgfd afecg cedgfa eabcd aefgcb afdgceb dfa fd eafcd debfga | afbgec gadebf fdcg acfed
cdagbe agefb fedabc fagcb gfebdac fgde baegd fe eadbfg feb | gebfa aecbfd fe bedag
adcfb bdcga df daf gdabfe cafdbe cbgfae decf becfa cbgadfe | gdbfcea fgebad fad bdacg
dcgef agc cfbadg ga afgec bcaefd efcba abeg cdeagbf aecbfg | dcfge fbgcae bdgfac fcgde
adcge gdcbaf bad cgdeaf bced abfge dgaeb db aedbgc ebdafgc | acebgd bad bad bdaeg
bgd adfcge gdacb fadb bd degfabc bcaeg dcfag gefdbc gbdafc | bceag badgc db cfdgbe
bdf cbadef ecafd bfacdg bd cbde baefd afcdeg ebgaf edagcbf | gdbcefa dcagfb bfaed dgacfe
cbdaf efbd ef afbec caefgd dagbecf gcadbf cbgea dbeacf aef | afbdc cgfdae caebg adgecf
gbfec ed fgebdc defacgb deb gedc cfebd fedbga cabdf abcefg | gedbfa dfbegac bgcef cbfed
dgc aedcg aedcf gd acegdfb cageb edgb dgcafb cbegfa ceabdg | egbd beacgfd aecfbg gd
abf gdbaef abgfc bf gcafe bdagc dbcagf cadbge bdfcgae fbdc | gfcdab fbgca adbegc cfbd
becfdga eac acedf cgbeda gafdec fabcd egfda ecfg dgaefb ce | cfead afdec gafed bfcda
bdgceaf febg bfacdg feacb gaebfc aebdc ef cfbga facegd fec | bcfga ecf cfbea acfged
baf geacf ab cfdebga cfbgde fgcbd gfbdea dbac gcfab adbcfg | bcdegf bgcdfa dgbfca gfcae
cd ebgcf ebdc dagbf fbgced fgecab cgd fedagc fbcgd fgecbad | fbcge bdafg cfdebga cbed
dfbcag geafc agdec da gad dgecb cgbfae faed edafgc adcgfeb | cagefbd dfbgca gdceb edcga
dfegac aegbf cg ceg agceb bafgde cebda fgbc cebgaf aedbgfc | bfcg efcbag ceafbg fbage
acdfg egd fcge fecdga ecbfgad eg aedcb eadcg gfebad adcfgb | ceabd afdegc aecdg gfbaed
fcbadg faebdc ga edga fcegb geadbf gefab bafde afg dcegbfa | fdceab bfgec fag cgefb
fbge bfeacg edabc dgbfca egdacf beacg gae fceabgd ge fcabg | aebgc abefgc bgef gcafb
cbe fedgb aedc ecbfga ec dabgc bfegdca degbc cgafbd bdeagc | fbedg fcbaedg dgcbe bce
gbdc cb edcfa bagfd agfedbc agfbde dfcab cfb gebafc cagdbf | bcf afgdb dbcfgae cb
bgdae fbagde cegdbfa aegfb fb dbfe gbfdca ecdabg fgb agecf | gadeb bgfade fcbaedg gabed
bfacdg ebcfda cgdfeb edbfgca feadg cfa gabc cgdaf ca cfbdg | ebgfdc bafgcd fgade afc
cgedba abcfge ade fgdbae edgaf egbaf edfabcg bfde ed gcadf | cfdga gaedfb adegcb fgecab
fbdcea bgdcf abfcgd gcab dcgbefa dafcb afbgde fgedc gdb bg | efcabd bcgdf badegcf acdfgb
ebdf dcafgb afdecg ebgca adbfg fe efg bcfdage eabfg agbfde | agcdfb badgf geadfc abefgd
daebc bedcfa def eacfg eafdcbg bcdf edgabc df dfcea gaedfb | fecadb gedbfa dcbea egbfad
gf gdcf cdabf bceadfg dfcgba cbagfe gdeba fbdag gfa dbefac | gedab cfgabe cfadb gbdaf
ced edcgabf dgfceb cdbg fbceag daefg ecdfg cd cfbge cabfed | ebdacf dec dce dacbegf

64
src/day8.rs Normal file
View File

@ -0,0 +1,64 @@
use std::convert::TryInto;
pub struct Entry([String; 10], [String; 4]);
fn parse_line(line: &str) -> Entry {
let parts: Vec<&str> = line.split(" | ").collect();
let unique_patterns = parts[0]
.split_whitespace()
.map(|s| String::from(s))
.collect::<Vec<String>>()
.try_into()
.unwrap();
let output_digits = parts[1]
.split_whitespace()
.map(|s| String::from(s))
.collect::<Vec<String>>()
.try_into()
.unwrap();
return Entry(unique_patterns, output_digits);
}
pub fn parse_input(input: &str) -> Vec<Entry> {
input.lines()
.map(parse_line)
.collect()
}
pub fn part1(entries: &[Entry]) -> u32 {
let mut count = 0;
for entry in entries {
for digit in entry.1.iter() {
let len = digit.len();
if len == 2 || len == 3 || len == 4 || len == 7 {
count += 1;
}
}
}
count
}
#[cfg(test)]
mod tests {
use super::*;
// I know it's ugly
#[test]
fn part1_example() {
let input = vec![
Entry(["be" .into(), "cfbegad" .into(), "cbdgef" .into(), "fgaecd" .into(), "cgeb" .into(), "fdcge" .into(), "agebfd" .into(), "fecdb" .into(), "fabcd" .into(), "edb".into()], ["fdgacbe" .into(), "cefdb" .into(), "cefbgd" .into(), "gcbe".into()]),
Entry(["edbfga" .into(), "begcd" .into(), "cbg" .into(), "gc" .into(), "gcadebf" .into(), "fbgde" .into(), "acbgfd" .into(), "abcde" .into(), "gfcbed" .into(), "gfec".into()], ["fcgedb" .into(), "cgb" .into(), "dgebacf" .into(), "gc".into()]),
Entry(["fgaebd" .into(), "cg" .into(), "bdaec" .into(), "gdafb" .into(), "agbcfd" .into(), "gdcbef" .into(), "bgcad" .into(), "gfac" .into(), "gcb" .into(), "cdgabef".into()], ["cg" .into(), "cg" .into(), "fdcagb" .into(), "cbg".into()]),
Entry(["fbegcd" .into(), "cbd" .into(), "adcefb" .into(), "dageb" .into(), "afcb" .into(), "bc" .into(), "aefdc" .into(), "ecdab" .into(), "fgdeca" .into(), "fcdbega".into()], ["efabcd" .into(), "cedba" .into(), "gadfec" .into(), "cb".into()]),
Entry(["aecbfdg" .into(), "fbg" .into(), "gf" .into(), "bafeg" .into(), "dbefa" .into(), "fcge" .into(), "gcbea" .into(), "fcaegb" .into(), "dgceab" .into(), "fcbdga".into()], ["gecf" .into(), "egdcabf" .into(), "bgf" .into(), "bfgea".into()]),
Entry(["fgeab" .into(), "ca" .into(), "afcebg" .into(), "bdacfeg" .into(), "cfaedg" .into(), "gcfdb" .into(), "baec" .into(), "bfadeg" .into(), "bafgc" .into(), "acf".into()], ["gebdcfa" .into(), "ecba" .into(), "ca" .into(), "fadegcb".into()]),
Entry(["dbcfg" .into(), "fgd" .into(), "bdegcaf" .into(), "fgec" .into(), "aegbdf" .into(), "ecdfab" .into(), "fbedc" .into(), "dacgb" .into(), "gdcebf" .into(), "gf".into()], ["cefg" .into(), "dcbef" .into(), "fcge" .into(), "gbcadfe".into()]),
Entry(["bdfegc" .into(), "cbegaf" .into(), "gecbf" .into(), "dfcage" .into(), "bdacg" .into(), "ed" .into(), "bedf" .into(), "ced" .into(), "adcbefg" .into(), "gebcd".into()], ["ed" .into(), "bcgafe" .into(), "cdgba" .into(), "cbgef".into()]),
Entry(["egadfb" .into(), "cdbfeg" .into(), "cegd" .into(), "fecab" .into(), "cgb" .into(), "gbdefca" .into(), "cg" .into(), "fgcdab" .into(), "egfdb" .into(), "bfceg".into()], ["gbdfcae" .into(), "bgc" .into(), "cg" .into(), "cgb".into()]),
Entry(["gcafb" .into(), "gcf" .into(), "dcaebfg" .into(), "ecagb" .into(), "gf" .into(), "abcdeg" .into(), "gaef" .into(), "cafbge" .into(), "fdbac" .into(), "fegbdc".into()], ["fgae" .into(), "cfgab" .into(), "fg" .into(), "bagce".into()]),
];
let result = part1(&input);
assert_eq!(result, 26);
}
}

View File

@ -5,6 +5,7 @@ mod day4;
mod day5;
mod day6;
mod day7;
mod day8;
use std::{env, process};
use std::fs::File;
@ -35,6 +36,7 @@ fn run(day: i32, part: i32, input_filename: &str) {
"6.2" => println!("{}", day6::part2(&day6::parse_input(&contents).expect(parse_error_msg))),
"7.1" => println!("{}", day7::part1(&day7::parse_input(&contents).expect(parse_error_msg))),
"7.2" => println!("{}", day7::part2(&day7::parse_input(&contents).expect(parse_error_msg))),
"8.1" => println!("{}", day8::part1(&day8::parse_input(&contents))),
_ => println!("Day {} part {} not found", day, part)
}
}