aoc-2021-rust

git clone https://git.sinitax.com/sinitax/aoc-2021-rust
Log | Files | Refs | README | sfeed.txt

commit 86dc2239e9836efc2f16cdb4ce1a56811641b480
parent c82c5d8d5b958f5f4b719e7bb2a59496443d753d
Author: Louis Burda <quent.burda@gmail.com>
Date:   Sun, 12 Dec 2021 12:33:22 +0100

Add day 8 solution

Diffstat:
Asrc/08/Cargo.toml | 7+++++++
Asrc/08/input | 200+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/08/part1 | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/08/part2 | 87+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/08/src/main.rs | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 552 insertions(+), 0 deletions(-)

diff --git a/src/08/Cargo.toml b/src/08/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc" +version = "0.1.0" +edition = "2021" + +[dependencies] + diff --git a/src/08/input b/src/08/input @@ -0,0 +1,200 @@ +gfeabcd adecfb gcedb cef efgdc decabg cbfg edfga fdegcb cf | fc faedg fdage fec +bcfegd fdceg ecgfadb fdae af cdeagf afc abdgc gcadf gfbace | cefdbg afgedc bcagd gedcf +gbf bagdec fgdbae cfbd bgacd fb fbcaegd dfgbac gbfca gecaf | gadcfb abgcf bdcgea gbf +eagcf cdgbaf cbadg fbcdgea cebfad fb fdgb abf gcdbea cgabf | bfdg dgacb gacef bafcg +bgface cfadb gfc gcfba febg aedcgfb bceag cdgaeb adfecg gf | acfdb fabdc efagdc facbd +bfegac adbfg ebagf beafgcd gfeadc age cgedbf gfceb eabc ae | acbe gfcbea aefgb abdgf +bfeag cbae cbg bc cbaefg cfdga fgdbec ebadgf eacgfdb gabcf | bfgcea eabc eagfb bc +abdcfg aebfd fbcade cdbge cfae eafcgbd dcabe bca degfba ca | ecfa fcadegb edbfag abc +dfcgea efcbg ecda fadgbc fac bdacegf ac feabgd afgde ceagf | fdgae abgdfc egcfa fagde +gfd gdcab fgdcae ecdfb bfdgc dacbef fbeg fg fdcgbe cdagbfe | bacgd cfdbea efacdg bcaefd +eb afbgd gafbe bef gacdfb gdecfab aecfg egdb defgab bdaefc | gacfbd bfaecd gabfdc bef +ecfb cbdfeg fgbadec fgcdb egf cefdg eagdc fbcdag fe gadbfe | fbgade bedfag gafbdc ecfdg +bafcdg gbd dbcgef ecgdf cbged cgabe faebgcd cgfeda db debf | bdg efdgc fbed gbcde +gdfceab afced decafb gadfc fg agdbc befcga fegd cgf cfegad | egdf ecafbg gbcda dcagf +eca ea efda cfbda badgcf dbcea edcfab abfcdeg bagfce cbdeg | efad fedcba fgcbea adfbce +gdefbca cf acbfg cegbda begca fbc gfebac afce gbdfa bdfgec | cbf bfc gecbaf cbafg +afcebd agebfc fbcea eadfbg bdf cdfa dfecb df cbdfgea becgd | ceagbf fcda becfd ebfac +ecb adgfeb fedbgca efac cfdegb egbaf ec bgcda gefbca cgaeb | afbdgce bec ec feca +eacdb dfcabe dg fdabgc cdg gaed cbaged gecdb ebgcf dagefbc | debgc dgaceb gcd fdebca +cega gdbefac gfdcb efbgca ga afg cgbaf aecfb ceabdf edgbaf | fedagb dbafce ga ga +efbadc acgde fagcde fe dcaebg edfg acgef cbagf fae acfebgd | ef badcef dfge gecfa +cbgfa cbae dabgef ba bag fcgea fdcage gfbcd cgbdaef gfecab | aefbgd bfgac gebacf bgfac +dgfbce fgc bfcda egdfa gc fgedab acgdf acedgf aegc fbcgade | dfagc bgdafe aegfd egfda +dgfa bedfc badcf agfbcd af eadbcg bfegca bfa cgabdef bgadc | bgdacf dcfba fcbda gbedafc +aceg gdaef fcbegda dcefab afcedg abgdfc cadef agf degbf ag | bdgfe bacfgd cadfe fcgeabd +bgefcd edg acdegb edcba cbdefa cfaeg beacgfd egcda dg dbga | efagc abcdegf adfceb dg +faedbc gabde becfgd caebf acfg eacbg cgabfe cdebfga gc gcb | cdgebf cefab abdfce gdcefb +de cgdfb edbg dbacfge cdfeg cebdgf agcef afbcgd dce dbfcea | beadfgc gbcadf dgcef degb +egcafb cgadfbe gdace fd bafce cedabf bgdefa dcfb afd ecafd | gaefbd dfcb aebcf gcabfe +cb beafcd bdgacf cdb bgac edgbfac cgfed bcgfd bgfdae gdabf | bafdg gcba fbgcd cegdf +fceba ag degafbc bfcga bcafeg agf bafedc gace bfdcg fedbga | bdefca fcgbd cbafe cgbdf +cafbge ce fbcea fecgdab aec adbcgf fbgca bgec baedf fegdca | defab bcfae ecgb aec +dgbc dagfcb acfgbde bad adcfg dabfc gacdef aebdgf cabef bd | acfdb defgca dbegfac gfdca +ecdf degfb adbge fcbgea dbgfec gfd df egfcb gacdebf cdfgba | cgbdfe gfd cfegab gfabce +defcbga fcade efbac fb gacdbe abceg abcdgf egbf fcbgae bfa | befg cabdge eafcb bf +cfbdae cg decbfag egfab fgdc dcbfe fegbc gce gdebca bfdgec | dcfg eadgcb ebdfc gfdcbe +eagcdf cfaeg dgfe bdcefa gcabfed cgbda cegfab dae cagde de | dae adbecf edfcga fdge +egfa gfbeac cfbag af fcgbe egbdfc abf cgbda ebfadc gbaedfc | cagefb edcbgf gebfc egcfb +gda ga bcadge gfea dcbgef adcfb fdebg cgbfdae gfdaeb fabdg | fegbd egaf dafgeb gda +gefad fegbad adecbfg db bed eacgb fcdgeb agdbe adbf acgfde | fabedcg bed gfadeb gedafc +fb cbefa baf dfbgca edfac gefbac eadbgc efbg gfecbad aecgb | dbacfeg degabc fgacbed febg +cbgfad eabcfgd cfdeg fbd adegb fb cfeb egbcfd fbegd agdefc | fdaegc febc fb ebgad +dbfgc badc cfdabg fgaceb degfab facegdb dgb efgcd fcagb db | gfbca cgfbd gacfbed fbgdc +efgcbd efbdc ef febdag dagfbc fcge bfdcg dabcefg edf ecdba | cbdegf defabg dcgabf bcade +ecdfbga cbdeaf bfgdc fca eagdfc eafdb bdfca ca caeb gfeadb | cbae dcbfa acf fgcbd +gdefcba bafd efcdab gecdbf fdc becfa gceda fd cafde baecgf | dfaec cabedf abcfeg df +cfb daefb bgfcde dgacb edfcagb acfe fdbcea dcafb cf febagd | fecdba dfcageb fabcd ceaf +adgbec fcgb badgecf dagcb bagefd fdb bf dcbfa bfadgc cfdea | fb efdac cfdba gadcb +afcgd bac gdebfca bcgaed afbcd ecdfgb dcfbe ba befa eafdbc | dcgfa dgbfce ab afcbed +gbcdaf fdgac bagde cgdbaef eabgcf bf gecdfa gbafd cdfb fgb | aecgdf bdega gafebcd aefgbc +gfeb cadfg bdfga aefgdb bgd bagdcfe bgeacd gb cebdfa efbda | dafebc bfadge dgb adcfg +cda dageb fgebda bfcdage dcbeag cgade cefbad ca cbga cfdge | gbadec febcad beadg cfbdea +gdabf eadgf fe defagcb abef feg gabcdf cedag dafgbe edgcbf | abgfde gedafcb cgeda adgec +fbd gfeba fgecad edafgbc dfcbga abdgf cadfg cgdb bd aecfbd | agfcbd ebacfd bafdg dagcf +cadefb cgde eg aebfcg fdbagce afdceg fbagd aeg dfage aedfc | gdaef fedca eg ecabdf +dgbeaf fcbdga ae agfcd egabdcf deac dcgfae acgfe fbceg gea | aecd dace gcbfe gcfea +dafeg fcg degbac gcdbe dcgef bdegcf gedbcfa cf ebfacg bcfd | agfebdc cegdf cf cf +bdfcea bdgae ecbga dbg fegbda bdefa dg dbacgf geafbdc efgd | bdg gefd cagbe debga +aegfdb afcbd cdaebfg dgafbc cagb ba dcefb fba cdagf fgadec | fedcb acbg bfcdga gfcaed +bfagcd agfb afcdg fcegadb dfgecb gb adbec gabdc efacgd gbd | eacbd adcfg fbgadc dbgca +fcedg dfgbea ea fcbadeg ade agefdc afcdb egca ceadf fegcdb | dfgce efcgdb dgecbf cfabd +dfea ed agdfebc eabfc bcdgfe edc cdbga ecbda aefdbc acfgeb | bdaec abfec gbedcf acbde +dgefcb fbcaeg fbcga bgfcaed bfgda dcbfag fgd cfda edbga fd | bgcfae abgdf acfgbe abegd +dgabfc cgdfe afd fdcae af agfe decba fcebdg dgfcbea dgfcae | fcaed fcabdg eafg fa +gafce debca gdfeca dfag dacbfeg fcbedg ceagbf fdc fd cadef | ecfad gcbefa begacf edbcgf +daceg efdcbg fcgad dbeca bdface bcfagde abge ged aecgdb ge | ecgdbf egcad eg aebg +fdbace debagc cgbef degba bacfedg gfda afb edfgba gbefa fa | fbdgcea befacd cdaebg fbaegd +fgbdea dg gdfb gfcebad abfeg afecgb dagbe edcgfa cdeba edg | egd fbgd dge eacdb +ge agdcfb fdcag fcbgaed degcf eadg bdcef acefdg bcfaeg gfe | aecfdg eg dcgfa caegbf +bcgef gfdb bgfcae fcadbge cedbg edafcg dg dcebgf bacde dge | agefbc bgefcd bedfcg dg +fga ga dcgfb dgeabf beadfgc eadfc gbca dcagf fadcbg bcgfed | ga dgcfba agcdf befcdg +dbag cafgbe cdfgaeb gabcde eabdc fdace bd bgcea gdecbf bcd | afdec abegfc gebacf edgabc +fcde cbadefg gdcefb bcdagf bcgef fdg abgcef edbfg df eabgd | egabd dbega gfcadb dbega +bfdag adbefc efdgcb fceab dbc cfdba egafbc dc ceda beacdfg | dbfcge cd fbcea efacb +dgaeb cgbeadf afbeg gdbfae ebadcg gdfb acgedf fg abefc gaf | fcdgbae gf bgaed fbaedg +cfdbeg dcfaeb cagbe cfgabde afdc fbaed cfe bfaec bgadef fc | fcaedb gbeac cfdgbe afdc +ceg dgecfa abecfg agcdfbe gcdae gfdcab fdec gbead ce acfdg | cgfad fgebca adbfgc dagcf +dcf cgebfa dc gdcaef eacgbdf cdefgb cebd dagfb cdgbf cfgeb | cd bgadf dbfga dgfba +gebac caefd bf bgacedf ebfdgc dbaf cfb bfeca agcedf dbcfae | debgcf adcefb befgdc gaecfd +abec bafgc fcebg fbaceg dcefgba degfb gec acdfeg ec fgdbca | dbgfe gdbfe ecgbf bcea +egafbd egdbc bdc cbfdag fcde ecbdfg fgbde ebcag debgafc dc | cdbeg fabedgc fgdecba dc +ecdgfa ag badcegf gaecb eabgfc adecbf cag acebf fbag dbceg | ebgac bfag dgacef edgacf +afgeb adgcbe efdb fgeacbd ceagf gbdefa eb bea dacfbg dabgf | eab bgfdea abfge bdfcage +egbdac aefdb fgdeb dabfc ea dae dbacfeg cagbdf caef eabdfc | cadbf ae dafcgb beadf +egcadbf gbce debac dge adfebc ecgad gdcfa dgcbea gdafeb eg | dgbfae ge adcegb bdfega +fecag dc fgecd dgcb edc fbedca dbcfeg gbedaf gfdbcae ebgfd | dce gbdc edgbfc fedcba +cafebdg adcfge debfac dgcae gec fbdegc ge cgdab faeg ceafd | gafe bagcd edfac cbagfde +dc bgcaf gdcebaf ecgdab cagdf efabcg dgc dcfb fgeda cgbafd | gbcfea dacebg bgfdcea dc +afedc ebfcg dgfbac adbe eafbdcg fdbce bd fbd bdafec afcdge | baed cfgade becdf dbcfea +bdae fbdac deafcb badcegf bcefga badfgc efcgd eb dcebf ecb | bcafdeg eagfcb dcbfag fcdbga +gb dafbce feagd bdegf bdcgafe fdgebc acdgbf cfbde ebcg bgd | adgfcb cgeb bceg dgbcfe +cbdfge bdceag fc edbgc dgfae bcdf fce bcefdga dgefc ebgafc | cdfge bgecaf fdgce cf +ba fcgae gecbfd cefbd cba afdbce aecfb beda fagdcb facdbge | ebad ecagf ba deab +ba baf ebacgf fcgad fbcdeg bgcef gadbecf ecfadb acbgf geab | cgdbfe ba dbceaf adbecf +cdfga efd efagcb egbd ed gacedfb fbdeca decgf gbcef gfbdce | cfedg bedcfg gecbf gbfce +fegbca ega egfdca gfeba afbec fadbg defacb gcbe eg dfagecb | ebacdf bdgeafc dfabg efabc +fdb efcbad bdaeg fbgade gfbe egacfdb adfgc bf dcebag badfg | dfcga bfd adfcg dgbaf +ead agbcd de bcgeda gedb agced cdafgeb bfcgda adefcb fecag | cbgead acdgb edacbf dfeabc +cagdfe egfca geacd dg gbaecf ged agfd cebda edcbgf decafbg | gbaefc ecgaf cgbaef gcfdbe +fd agcfedb adgfb cdaf degab bfacg cebgfa bdgfec fbd dcgbaf | abdgcef dgacbf cfda cedfgba +cafbd fgcb bgcad gdfcba eadbf adecgb cfa efgadc agcdefb cf | fc fdbcag fgeadc fegdca +dgcf eadcg fg dabfe gdefa efg cegabd fadecg gadfbce facbeg | aecbgd gceda gdecab abcgfe +ebfdca agbdcf gfadc bfc afgb cdgaef egcdb gbedfac fb dgbfc | ecbfadg baefdc bf dbgec +fabcge cafged beg abfdge aegdf dabg fgbacde bg fdebg bcfed | efgda dgefba gaefbd bagd +gbfda afbcgd acefdg adb bd gbfae dfcga acegdb acfdegb cbdf | dbfc abd bd dcabfg +ecgdf abcedf gfcdba eadb ecb fdcab fecbagd be eacgbf ebfdc | gdbcfa ecfdab deba efbagc +ca fcda efbdgc ebgda bgefacd cea cdebf bdefca efagbc ebcda | fgebca egabd edcbaf acfd +agebd dcge ed gaebc fegacb cfaebgd bcedfa gfbad dbe cdgeab | dbega fbeacd gaebcd gfcabe +bg edfagb daecgf bgafdce bdeag cgbdaf ebgf ebdac bga edfag | dabcgf cbaed ecdba abg +efdcg afbd bfdeg bgf fgdaecb dagceb fb gcbafe abgdef egbad | fbeagd bcdafge gdbfe fgdbe +becfa fg dgfe dfaegcb cedfbg begdca fgceb facbdg bfg gebcd | fg gebdcf dcbega cdegb +edgacb cb cefdba gcaefd adcbg cdb cbge efgdcab gdeca fadbg | gcabfed cb acgdbe gbafd +cfgbde eagdbc cegdb ebcf bdf fb fbgde facedgb eafdg dcbgfa | cdfagb cfbgde bf dfegcb +gedcfab ebfcda ecdbf gfced fcebdg gcd gdeaf cg cdbgae fgcb | cedafb gdfecb cg gc +fbe edbfca feadbgc cbefga fb dfaeb abdge eacdf gfedac fbdc | fadeb acbedf fbdae daecf +dgacbef efgba dgbfe fecabd bgaefd bde dfcbg de aedg bfgeca | bdfcg ebfdac eagfb gdae +efbgcd aedgcf acd cafbd gbfdaec bagc bcfgd ca gdafcb dbfae | bcadgf beadf ca fgcadb +edgfba fbged aed gadcb bdgae ea efga cdbefa cbefdg dcabgfe | dfbcae bfceda ae gbaed +gdc dfgbeac adcf bfecg abgfd bcdfg dabfgc cd fbgdae dbeacg | gcbfd fdgba afgdcb gbdcae +ca acd ecfbdg fcdeb cdfbea gcabfde afdce cbaf afedg cgadeb | cdbef ca dbecf agfed +gfceab ed fgecd fdgaec gdbfc eacfg cdegfba dcae deabgf efd | eagdfb ed cefag aced +baced dg deabfg dga adcge gcfd acgefd acegf acbdfge fabgce | egfdac becad aebcfgd gcdae +ed dec cdabgf acefb ecbfdga becagd gdbac cedbgf adeg edcab | bdagc acebd bdfgac gdfbcae +gefbca edbfc agdf bgadce fegadc ceagf gafdbce ecfgd dg gcd | gdfaec bfecagd gacefb acgbefd +cdega fcdbga gbfceda gafbde adgcb egfcd ceba dea badecg ae | aebgdc dfbage badfge edgcf +egcdfba ebcga gfe adgcef gdbf bedgaf gabfe dbefa fg cbdfea | gdfaec dfbg abedf gcdfae +feabc gdfeab ebgdafc fa cebga cadgeb gafc fbgeac ebcfd fea | gcabe cbgea febadg fcag +afdb agdfe bdcafge fdaegb aegbd gefdc abdecg aecfbg afe af | fae adfgbe af degab +fdg cdafgb fg cdbef bgfde gfea edbag ebadgc bgaefd adfcegb | befgd dfbgca baedcg gedba +aedgfc afegbcd ag bcedga bedafc aedbc agd gbcda baeg gfcdb | edabc gaeb afedgbc agfdce +eafdc db fcgbe dbac dcbfaeg ecfbad bdf bfced beafgd aedcfg | cdba bd cbafed db +cf fcebgad adfeb afdbce afgcde debgc cbdfe cafb cfd dafgeb | bdecg aegdfc cf dbcegfa +dfceab cebgad fgcbade dae ecdgb bgae dagec fdbgce ea dcagf | eagb ceabdf dcfeab badgce +dgf agcfed gacf afcde dgcef dgaefb efdacb egbdc fg bdeafgc | acdef afgc gdeafcb fdegab +abc aegfcb bc aedgbcf abdce eagdc gdceaf bdfae dcbg aedgbc | fbacge cadgbe gcaedf fdeba +ebdagf ac gcbfe agc aebgc gcbfeda cbdgfa edabg dcae acbdge | cbgfad cag dgfbca abfegd +cdafbge bgf afgd adcebg acefb gf dbgca agdcbf gacfb cfdgeb | dagf dacgb cfabe dbgfce +ebgfacd eafgcd dbcafg ebcafd gdeac afeg eac bcgde afgcd ea | fdbgac dfgca ceafbd gfbacd +gfeb gcdbfea dbecg edacgf fbdac efcdb fbdgec acbedg efc fe | cedbg bcfad ef fec +gfbecad faegb gcdfea cfg gc bceg bagfc fagdeb bacdf fcabeg | aefgcb cfg dafbge agbfdce +bfcedg decba agcf abegfd bdceagf bgacfe cg cbgae efgab ceg | fbceag eabgfc gc abgfec +adebcf agbef abegdc bedgf cfbadeg bedcf fgcd gd bcdfeg gdb | cbafgde dbefc gdb abefg +aeg cdabeg cgfadb aebgd ge ecafgdb edbfa acgdb gafedc gecb | cbge agefdbc cgdafb fdabe +febag ceba ceagf dabfge gce cabedfg cadfg efbcga ec fbdceg | edgcbf bgefa fecag afcgd +faecdb cea dabfgc dfagceb baed dgfcae caebf ebgcf ae bdacf | ae fbaecd ebcgf bcfda +gefc efbdga ec bdgfe fcbeda ecadgbf cbgde cedgbf bce bcgda | ce bec ecdbg gcbad +dbaegcf dbgaf agbde dcebfa gfdc fcabg gcfbda df ceafbg dfb | becdfa dbf egafcb bfagd +gfdae gbfec egcdf afbceg bcdf acgdbfe dabcge cfegbd dc cde | fcdgeb dbagec cafbeg gacebd +fg edcgafb fcadb bdgae fgbda ebdfac fabcgd gecfdb gfd gafc | cefgadb fg cbfged gf +bdfea fceba fc agbce ecdgfab gcefad fec aebdgc bcegfa cfgb | dbfae efc ecbfga gdceaf +cdfgb gefcda abdgce beagd ec bcae dbgfeca ecg ebdgc abfedg | dgabe adgcfe fdcbg ec +fbedc egfabd gadcf dcfeg aecdbgf gcea eg dafgec fcdagb fge | bafedgc eacg ecdfg deafgb +faegdb fdb bgfdec bcgda agfebc gcebdaf cedf gdfcb cfbge fd | dbegacf cfaegb gfcaeb befgac +gbacdfe fdgcba befgc fabe bcf edcbg cgfeab cfaeg fb acdfeg | cfeag bcgde ebaf fgcdab +gef dceg edfbc baedcf bdagef eg cfegb bfacg afgbced decfbg | dfegba cfegdb eg gacfb +cba adgcfeb abfdce dgecbf ca ebdacg becdf adfc fbeac fabge | fbaeg gfbceda fceba bdaecf +cb adefc egcb abc bedgac ecdab bdfgca eabgcfd edagb dabfge | bfdega fagcbd abcde agdeb +dgfbae efgbacd gcdf bdg gd bcgdfe bgcde bedac cgbefa bcgfe | gbd aedcb ecfbg ecdbg +gcafedb ecdbfa fedcg dcefga dfgca gbcde gfae ef fec bdfcga | fdgcabe cbadef fcgda ebdgc +eca ea fbadec debcg agef edcga caedgbf fadgc dgafec cfbgda | cbdeg cedgbaf aecdfb dcgea +afc gbafec egbdfca ca eagbfd aecgf abfeg gcba abedfc dfgec | gafbe cedafb afbeg cagfe +agbde eabcgd fe dcfgb efd becdgfa dfageb fdebg fdcage bfea | def edgfb acfedg bgead +gbdec facbgd ag gba bgceda aedcbgf eagd cgabe bface fbdecg | eagbc gcbdfa bafcgde eacbf +dbacfge cagfdb geba cefgda bgc eacgf caebfg cbdef bg fcbge | bg abcegf efgca cfdeb +gaefc cgefdab fdcaeg aegfdb gb badfc gbf bcfag gbfeac gceb | bdafc aefgdb gfcae dfcab +dbceg bcafgd cfabde cfabdge aed ae deacb face egfbda bfdac | cgabdf fgeadb ade dcbge +dfbgcea fbeca cefbg dfgc bgaefd dbecga gfe fg efdgcb cdbge | gcbfed cfbeg gdfecba gecbd +gaced bd edfcag aecdfgb bgad edcbg debfca deagbc bdc egfbc | bdc cdb efcbad dagb +egfca bgea adebfc gfceab cfebg cdefag dgfbc bgadecf ceb eb | dcefag facgeb edbfca eacfg +fged bcaeg fcgbde gdfacb fcadbe bfcge ebfcd fcg edabgcf gf | gfbdac efcdb gfceb fgdceb +fgbdeac facdb agcf fc bfegcd bedfa gbcda bcdfga fcb degacb | bgecad cf dcgbfea gfca +dafbgc cfdga dgafeb db cfdage bcfaedg fbgec bdf dcab cdbgf | cfdgb befadg ebgfc acdbfg +eadgf gdefab ebacd fc eafgcd caf deafc egcf dacbegf bfdagc | egadcfb agfdcb debca fdcagb +dgaecb efd gbecdf fgdcae geaf faecd dfcab bcfagde egcda ef | fe ecagd efd fed +dbaf bf bfg ebfcga degba cedfg adfcgeb edgfb begafd daecbg | cbegda cbeadg fbg cgfde +gdebcfa cbfad ecgfd fbeg dgfbc bg gfcade gdb gdbecf gdbeac | fdcgbe begf acgedb cbdfg +acfdge cadgbf gecfd dbefc fg agcebfd cfg gedac adcbge efag | egaf cbdgeaf gfc bdfgca +fbgad eabg bcdafg bde edcfab fdgec degbfca badgfe dbgfe be | egbdf bgadf bfdge edgfc +gfceab acf ceafbd cagdbe bdaf dcfae af febacgd fgdec daebc | cegfd dacfbe faebcd adfecb +bgefcda facgb bcg fgec cgebad gc efagcb bdgaf fecba dcfbea | bfeac acgfb ebcaf bgadf +eagbd abcgde afedc gcbe bac debcafg bgacdf bc dbcae gadbef | cba adcfbeg efdac cb +fbead gdebfa cabge adfbgce dcb dc aebdc dacfeb dcfa gbfecd | decfba cd dc edcgfb +gcbae ecfbag gebcf edabg efagcd cga ac beagcdf bcfgde fbac | fgecb gdabe agc ca +dfgacb fadbg afebdg acbgefd gdbc cgafd efgac cd beafcd fdc | daebfgc cebfad bgdeaf dcf +cfdeab efgadc cfbag ef cagbed dbcea ecfab cfe befd gecdfab | fgecdba cabde abefc dbcae +fadec cbgade acbfe df cdf acfdeg afdg gabcfed acged bfdcge | efcda ebfca ebgcfad dcage +cdfgeb eabgcdf faegc facgbd gdc efbdac fdbca fdgca gd badg | dfbceg cfdba cfgda bcadf +cdeafg ecfbgd cb eabc aegdcfb cdfba bfc cdfeba edfac dagbf | ceafdg feadc fbegdc beacdfg +acfbde agc cabgf cfdba gfecb bgadce bcgfda fadg cebdgfa ag | cbfad cebfagd agdcbf dcabf +dfeag fgbedca dfceg fcgaed egdcfb edbcga aefc gfadb aeg ae | gefda gabfd egacdf dfbgec +gfbec bdcaegf cdb bdacgf dgcbae gdcaf cfdage bd badf dbfcg | gaedbc dcb fcgdb afdbgc +cgdef geafc fd fdgbac degbc dgcefba cfeabg dfae cafdge dcf | egbcfa defa df dcf +cafed gdbfa cbfade cfgead cb gecbfd gdbcfea bcea cfb bacfd | bcea afdbg cbegdfa afdcbge +ac fcdgeba gdfec bdgefa fedab eac fadce aecbgf dbac aedcfb | efgabdc cafde bacefd cfeagb +begcf eagcdbf cfg bdcfea bfeca cfdagb bfged caeg cg acfegb | bgfde dgafceb dcfeab dgacfb +gbdfca fadbg fbc cb bdfgae abgcf feacg dfabceg dabc cfgdeb | cbf fcgdeb eafgc bdfgea +fcaegbd abgdce fdcgab gf bfgcae bfg gbfea abgce fgce ebadf | fdabgc gcfabe aebgdfc gbdcae +cdagbe gedbacf efbcad ebdag be gbcfad gbdac ebcg ebd egfda | efgda ecgb gbecda bdfgca +bfdgac gdecb abcde daefc efbgcd ecdbga agbe dab ab cfgabde | ebga ab cgbfad eacdb +efgda ac acf dfgbec dfeac edfbc ecfdgba fceabd bfdcga aecb | ecadfgb abcedf cefad cabe diff --git a/src/08/part1 b/src/08/part1 @@ -0,0 +1,99 @@ +--- Day 8: Seven Segment Search --- + +You barely reach the safety of the cave when the whale smashes into the cave mouth, collapsing it. +Sensors indicate another exit to this cave at a much greater depth, so you have no choice but to +press on. + +As your submarine slowly makes its way through the cave system, you notice that the four-digit +seven-segment displays in your submarine are malfunctioning; they must have been damaged during the +escape. You'll be in a lot of trouble without them, so you'd better figure out what's wrong. + +Each digit of a seven-segment display is rendered by turning on or off any of seven segments named a +through g: + + 0: 1: 2: 3: 4: + aaaa .... aaaa aaaa .... +b c . c . c . c b c +b c . c . c . c b c + .... .... dddd dddd dddd +e f . f e . . f . f +e f . f e . . f . f + gggg .... gggg gggg .... + + 5: 6: 7: 8: 9: + aaaa aaaa aaaa aaaa aaaa +b . b . . c b c b c +b . b . . c b c b c + dddd dddd .... dddd dddd +. f e f . f e f . f +. f e f . f e f . f + gggg gggg .... gggg gggg + +So, to render a 1, only segments c and f would be turned on; the rest would be off. To render a 7, +only segments a, c, and f would be turned on. + +The problem is that the signals which control the segments have been mixed up on each display. The +submarine is still trying to display numbers by producing output on signal wires a through g, but +those wires are connected to segments randomly. Worse, the wire/segment connections are mixed up +separately for each four-digit display! (All of the digits within a display use the same +connections, though.) + +So, you might know that only signal wires b and g are turned on, but that doesn't mean +segments b and g are turned on: the only digit that uses two segments is 1, so it must mean segments +c and f are meant to be on. With just that information, you still can't tell which wire (b/g) goes +to which segment (c/f). For that, you'll need to collect more information. + +For each display, you watch the changing signals for a while, make a note of all ten unique signal +patterns you see, and then write down a single four digit output value (your puzzle input). Using +the signal patterns, you should be able to work out which pattern corresponds to which digit. + +For example, here is what you might see in a single entry in your notes: + +acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | +cdfeb fcadb cdfeb cdbaf +(The entry is wrapped here to two lines so it fits; in your notes, it will all be on a single line.) + +Each entry consists of ten unique signal patterns, a | delimiter, and finally the four digit output +value. Within an entry, the same wire/segment connections are used (but you don't know what the +connections actually are). The unique signal patterns correspond to the ten different ways the +submarine tries to render a digit using the current wire/segment connections. Because 7 is the only +digit that uses three segments, dab in the above example means that to render a 7, signal lines d, +a, and b are on. Because 4 is the only digit that uses four segments, eafb means that to render a 4, +signal lines e, a, f, and b are on. + +Using this information, you should be able to work out which combination of signal wires corresponds +to each of the ten digits. Then, you can decode the four digit output value. Unfortunately, in the +above example, all of the digits in the output value (cdfeb fcadb cdfeb cdbaf) use five segments and +are more difficult to deduce. + +For now, focus on the easy digits. Consider this larger example: + +be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | +fdgacbe cefdb cefbgd gcbe +edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | +fcgedb cgb dgebacf gc +fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | +cg cg fdcagb cbg +fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | +efabcd cedba gadfec cb +aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | +gecf egdcabf bgf bfgea +fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | +gebdcfa ecba ca fadegcb +dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | +cefg dcbef fcge gbcadfe +bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | +ed bcgafe cdgba cbgef +egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | +gbdfcae bgc cg cgb +gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | +fgae cfgab fg bagce + +Because the digits 1, 4, 7, and 8 each use a unique number of segments, you should be able to tell +which combinations of signals correspond to those digits. Counting only digits in the output +values (the part after | on each line), in the above example, there are 26 instances of digits that +use a unique number of segments (highlighted above). + +In the output values, how many times do digits 1, 4, 7, or 8 appear? + + diff --git a/src/08/part2 b/src/08/part2 @@ -0,0 +1,87 @@ +--- Part Two --- + +Through a little deduction, you should now be able to determine the remaining digits. Consider again +the first example above: + +acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | +cdfeb fcadb cdfeb cdbaf +After some careful analysis, the mapping between signal wires and segments only make sense in the +following configuration: + + dddd +e a +e a + ffff +g b +g b + cccc + +So, the unique signal patterns would correspond to the following digits: + + + - acedgfb: 8 + + - cdfbe: 5 + + - gcdfa: 2 + + - fbcad: 3 + + - dab: 7 + + - cefabd: 9 + + - cdfgeb: 6 + + - eafb: 4 + + - cagedb: 0 + + - ab: 1 + + +Then, the four digits of the output value can be decoded: + + + - cdfeb: 5 + + - fcadb: 3 + + - cdfeb: 5 + + - cdbaf: 3 + + +Therefore, the output value for this entry is 5353. + +Following this same process for each entry in the second, larger example above, the output value of +each entry can be determined: + + + - fdgacbe cefdb cefbgd gcbe: 8394 + + - fcgedb cgb dgebacf gc: 9781 + + - cg cg fdcagb cbg: 1197 + + - efabcd cedba gadfec cb: 9361 + + - gecf egdcabf bgf bfgea: 4873 + + - gebdcfa ecba ca fadegcb: 8418 + + - cefg dcbef fcge gbcadfe: 4548 + + - ed bcgafe cdgba cbgef: 1625 + + - gbdfcae bgc cg cgb: 8717 + + - fgae cfgab fg bagce: 4315 + + +Adding all of the output values in this larger example produces 61229. + +For each entry, determine all of the wire/segment connections and decode the four-digit output +values. What do you get if you add up all of the output values? + + diff --git a/src/08/src/main.rs b/src/08/src/main.rs @@ -0,0 +1,159 @@ +use std::fs; +use std::env; +use std::collections::HashMap; + +fn main() { + let args: Vec<String> = env::args().collect(); + if args[1] == "1" { + part1(); + } else if args[1] == "2" { + part2(); + } else { + eprintln!("No such part\n"); + } +} + +fn part1() { + let content: String = fs::read_to_string("input").expect("no input"); + let display_digits: Vec<Vec<&str>> = content.lines() + .map(|x| x.split_once(" | ").unwrap().1.split(" ").collect()).collect(); + let accepted: Vec<usize> = vec![2, 3, 4, 7]; + let mut count: u32 = 0; + + for digits in display_digits { + for d in digits { + if accepted.contains(&d.len()) { + count += 1; + } + } + } + + println!("{}", count); +} + +fn code2bin(code: &str) -> u32 { + let alph = "abcdefg"; + let mut val: u32 = 0; + + for c in code.chars() { + let index = alph.find(c); + if index != None { + val |= 1u32 << index.unwrap(); + } + } + + return val; +} + +fn bits_set(bin: u32) -> u32 { + let mut cnt: u32 = 0; + + for i in 0..8 { + if bin & (1u32 << i) > 0 { + cnt += 1; + } + } + + return cnt; +} + +fn decode_value(codes: &Vec<&str>, out_codes: &Vec<&str>) -> u32 { + let len2code: HashMap<u32,u32> = HashMap::from([ + (2, 1), + (3, 7), + (4, 4), + (7, 8) + ]); + + let original_mapping: Vec<u32> = vec![ + code2bin("abcefg"), + code2bin("cf"), + code2bin("acdeg"), + code2bin("acdfg"), + code2bin("bcdf"), + code2bin("abdfg"), + code2bin("abdefg"), + code2bin("acf"), + code2bin("abcdefg"), + code2bin("abcdfg"), + ]; + + /* calculate correlations */ + let mut overlaps: Vec<Vec<u32>> = Vec::new(); + for cur_code in &original_mapping { + let mut shared: Vec<u32> = Vec::new(); + for cmp_code in &original_mapping { + shared.push(bits_set(cur_code & cmp_code)); + } + overlaps.push(shared); + } + + /* find digits 1, 3, 4, 7 */ + let mut remaining: Vec<u32> = Vec::new(); + let mut mapping: Vec<u32> = vec![0; 10]; + for code in codes { + let digit = len2code.get(&(code.len() as u32)); + if digit != None { + mapping[*digit.unwrap() as usize] = code2bin(code); + } else { + remaining.push(code2bin(code)); + } + } + + /* infer rest of digits */ + for code in remaining { + let mut fit = false; + for digit in 0..10 { + fit = true; + for cmp in 0..10 { + println!("-- {} {} --", digit, cmp); + let cmplen = overlaps[digit][cmp]; + if cmp == digit && bits_set(code) != cmplen { + println!("wrong length"); + fit = false; + break; + } + + if mapping[cmp] == 0 { continue; } + if bits_set(code & mapping[cmp]) != cmplen { + println!("wrong # of same bits: {:08b} & {:08b} != {}", code, mapping[cmp], cmplen); + fit = false; + break; + } + + println!("{} {} ({}) : {:08b} {:08b}", digit, cmp, cmplen, code, mapping[cmp]); + } + if fit == true { + println!("add {:08b} => {}", code, digit); + mapping[digit] = code; + break; + } + } + /* ensure we found a digit */ + assert_eq!(fit, true); + } + + /* decode output */ + let mut output: u32 = 0; + for code in out_codes { + output *= 10; + output += mapping.iter().enumerate() + .find(|v| *v.1 == code2bin(code)).unwrap().0 as u32; + } + + return output; +} + +fn part2() { + let content: String = fs::read_to_string("input").expect("no input"); + let lines: Vec<&str> = content.lines().collect(); + + let mut sum: u32 = 0; + for line in lines { + let sig_codes: Vec<&str> = line.split_once(" | ").unwrap().0.split(" ").collect(); + let out_codes: Vec<&str> = line.split_once(" | ").unwrap().1.split(" ").collect(); + sum += decode_value(&sig_codes, &out_codes); + } + + println!("{}", sum); +}