aboutsummaryrefslogtreecommitdiff
path: root/2021
diff options
context:
space:
mode:
authorJulien Dessaux2021-12-09 17:54:15 +0100
committerJulien Dessaux2021-12-09 17:54:15 +0100
commit984d3d5ebb1be5e87773dd8a435e8cfd4039f4fc (patch)
treefe8a556ef488da120750d02c5fc5692e47effd02 /2021
parentAdded solutions for 7th day (diff)
downloadadvent-of-code-984d3d5ebb1be5e87773dd8a435e8cfd4039f4fc.tar.gz
advent-of-code-984d3d5ebb1be5e87773dd8a435e8cfd4039f4fc.tar.bz2
advent-of-code-984d3d5ebb1be5e87773dd8a435e8cfd4039f4fc.zip
Added solutions for 8th day : the seven segments code to guess
Diffstat (limited to '2021')
-rw-r--r--2021/08/example10
-rw-r--r--2021/08/first.go25
-rw-r--r--2021/08/input200
-rw-r--r--2021/08/second.go143
4 files changed, 378 insertions, 0 deletions
diff --git a/2021/08/example b/2021/08/example
new file mode 100644
index 0000000..c9f629b
--- /dev/null
+++ b/2021/08/example
@@ -0,0 +1,10 @@
+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
diff --git a/2021/08/first.go b/2021/08/first.go
new file mode 100644
index 0000000..d21fe67
--- /dev/null
+++ b/2021/08/first.go
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "strings"
+)
+
+func main() {
+ score := 0
+
+ s := bufio.NewScanner(os.Stdin)
+ for s.Scan() {
+ inputs := strings.Split(s.Text(), " | ")
+ output := strings.Split(inputs[1], " ")
+ for _, v := range output {
+ l := len(v)
+ if l < 5 || l == 7 {
+ score++
+ }
+ }
+ }
+ fmt.Println(score)
+}
diff --git a/2021/08/input b/2021/08/input
new file mode 100644
index 0000000..b74fad4
--- /dev/null
+++ b/2021/08/input
@@ -0,0 +1,200 @@
+bge dacgef gefac geabf gcab baedf efbdgc agcfeb gb edacfgb | dabef caefg gb gfabe
+cefgda agcbf febcda dc bfeda bdec cabfd dbafge febgacd dca | gafedc dfcab cd abgcf
+fabe gfdcea cbdga fgbdec dacfbeg geabc gaecf be agfbce beg | ebacfg fegdca agceb bafe
+gb fegac dgbafc dgba gdbfeac fcbade edcbgf fgacb bgf abfcd | cfedbag gbf fgcea agdb
+fedgc adecbgf fec fcabde fc fgbc edcfbg aegdf egcdb gebdac | gecdf fc defcg cgdeab
+edgfac fcgbea fdbca dcgeabf gceba ed edcgab debg edabc ade | dbcaf cgfdbae dbeg egbdcaf
+cbagef fdcga dgaefb de acfeb ceafd ecbd dfabec bcfdega ade | ed dbefac cafbed ed
+dfecgb afcde fg cbdgfa edbgac cdfag dbfgeca gcf gbfa gdcba | fg bedfgc bdcafg gbfdeac
+ecagbf eba eb gbefa gfabcd efcb ebagcd gcfabed abcfg gefad | dfcbga efbagc eagcdbf be
+fce bcagf bcdgaef agbfdc efbda cebdfg geca gbecaf bceaf ec | gcea abcef cefab cbgaf
+fdacbe gade gbd gbdfca dg cgdefba fecgb gecdb dbeca cabged | egad eadg ebcgd cbfeda
+bcgaef dcbgfa ecgd gd bgade cebag gbaecd fadeb dag fcaedbg | dg aecbfg dg edgc
+dbafg cadbgfe eacfg afgeb begcaf bgce bae ebafcd dcgaef be | bfgad eb gfaeb aegbcfd
+abg fadeb acgef cgeb gbfcea bagfdc aegbf adebgcf aedcgf gb | dfbea dfgcae ebdfa afbgdc
+gb agedc bcgaef dfacbe acbfe egb begac gefbcd dbgcaef bfga | bg bgecdf cbfaged bdfgce
+fbac adcge ba abe cfdegab aebdcf gcdbfe fgdabe adbce bfecd | cgdfbea adebc bedac cfdgaeb
+egdfac cfa adbfce cdbfge cebdafg cabeg efdcg fa efgca fadg | dbfgcea cfgdea fa egcab
+abdgfec dbac dbgef bga fgcbea ba gcdea decgaf dageb dcabeg | abgedc bga efdbg adcgbe
+caebd gecaf gb gcdaeb afbdce geabc gfbdea bag agdfcbe dcbg | gba abegc gb gab
+bgdfae fadcge aef ef dafeb bgef abegd fcdeabg fdcab gdbace | dgabe gacefd fgbe abedf
+fdecga egdac gdefcab ae fegacb dacgf eag gebdc cagdfb efda | cfadg edagc gfdeca ae
+dge cdbgea cegbf dgecb daceb dg eafdgbc gbda cgfade baedfc | cadgef bgcef gcadbef decab
+fdeagc eacgbf befagd cdfeb dbga feabd da eabgfcd gfbae adf | adf fda da edbgaf
+egcda ab gebcaf cabeg befgc adefcb eab cdeafbg gbdfce gfab | fgebc ecgfba cbfgde deacg
+dbfcga adbcegf agd caged degf fdgcea cgeaf gd ebagcf bdeac | dfabgc bdacgf bacgef gd
+gcfdae ged ge edbagcf dbgef bgce efdba fedbgc fgdcb adfgcb | afgbdc agbfcd aebdf gfedac
+gafdeb bd ecfdgb dbaf decfbga cgeab bde agdfe gfdcea begad | aegbc gbace acebg caefgd
+edgbc fgdac bgef dfb efgdbc gcaedb fb fadbcge gcfdb afbecd | abcdfe dbceg agecbfd fb
+edbac cdbef cedfgba ba dba fbaged gbac decgba egcda cfedag | edgbac edcba ba dfcaeg
+faceg df acdfge fedca gdaf fegacb gcdfeb cfeabgd ecbad dfe | fd cgefad eafcd dfag
+fcabd cbe gfcbea ec cagbfde dbefag bafec ecag edgfbc gbafe | afbeg geacbdf cbe afbge
+gbfdae cebfad cdfeg ga fadbe adbgfc adg baeg gacbfde gfade | bgeafd aefdcbg gda fcdbag
+cbgf fecba gc gcabde agecf agdef adbegcf cegfab ecg fbaedc | ecg cfgedab cdbgae cfgbade
+abcged dcgef fdeag gbdcf edc gafdecb fbgdea ceagfd ce afce | aecf ec cdgfeab cafe
+begfdc geb faeg abfdcg efacgbd dgfbae eg fadbg abdeg dcaeb | fbagd fgea gbedcf dgafb
+agecd faegb db egbfda bgeda ecbgdfa bgefac gcfdba fdbe dgb | gdb fdbe efbd fbeagc
+aedgcb df adcbfeg gefd befdc bfdagc bgcde fdb gbedfc aebcf | degacb fd fdge gedf
+fgbeadc ced acdb edbgfa fcgea dc dfabe fbcgde edabcf fadce | ecd egcfa fbcdge cd
+dcabfe adgbe gafed fdgeab dfgb fecagd bgace db ebcdfag edb | fbdaeg dafbeg gebda gaebfd
+bcadg bagecf cgfd gadbe adcfb fdbgaec fgabdc gc bgc ceabfd | egdcabf afgbec cabfed dbagcf
+dgeabfc ega cagfb feagcb gedfb ceaf dbgfac ae eafbg bdagce | bcagf aeg feac ae
+gbec bcgaf ge ecbafg eabfcdg cdgaef fcgbda fge fadeb fbeag | ge bgce edgfcab gadfcb
+fca fecabgd dafe fadcg gecda gcabde dcfbg dcafeg aebgcf fa | af dcfbg fead bgecafd
+gcfeba bg cdbfa adgbcf gdba fbecagd fgcde eadfcb bgc fgbdc | dacbfe bacdf fcgdb dgab
+abfcd cefg gdcbe gcbade fedcbg fde bedfc cabdegf ef fbdage | bedfcg gcebd def edcbga
+cadeg bc cbd gabfd adbcg cbfgead adgbcf efabgd befcdg afcb | gdfaeb bafc gbafd gfdcbe
+bfcgd ca cage dcfga fca becadf fgbcdae gacfed fgbeda gdfea | acf cfa acf ca
+bedac dfebca gcaeb agdb acg bdegac ga fgdabce cdfgea befcg | daefcg dgacbe ga cdegfa
+ga bga acedbf gbdec cgaefb faedb ebgdaf fdag bdgea cgbfead | cdbge becgd afcebd bag
+gb aefgcd gba febca bfdgca fcebdag cegba gedb ceagd gdbcae | dagce bg abg abg
+deba agdfceb gbeac cbdge ed efadcg cegbfa deg gbcfd decgab | cfdbg ged gbcfd ed
+cefga fe bcfag acebgd fae gdeac feadbg gcbefda efdc fgecad | ecfdag fe fgeac afe
+afbcdge aegcf feadb bgec fcabe bc cfagdb fbc fcgaeb dfeagc | gceb fcb beacf cfeba
+dagcef cb gbfed adcef decfb cbd fabc bdgceaf gdbace bcdfae | cb bcd gacdbe adbfgec
+beafg bdf adfec db acdegf bdca dbaef egbfdc cgbdfea bfadec | fbega egdbfc bfegcad cdab
+ecbgf bacd agdfcbe bfeca bea badfce afcde acfdeg ba gdefab | abe ba aebdfg aeb
+gecfbd fe fde egdabf dbagf edagf efba aedcg efbagcd fdcgab | egadf agdcfb fbea cagdbf
+cfgab abdgce ag bcfae abg cbfgd bacdef dbfeagc eacbgf gfae | gba abegcdf gafe ebgcfa
+egd bceag cedbg bfegac fgdcb ed ecdabg cafgbde bgedfa ecda | dbcge edcgb aedgbf cebdga
+gabde agf debafgc cdbfa gefadc fbdga gf fcgb acefbd bdcgfa | gfa eagdfcb abdfc gf
+dfba gcabe becfgd gacfd gbf facbged adfbgc ecfagd cbfga fb | dafcg dcfagb ceabg fgdac
+bfa afbecgd bgacef gbfda dacefg bf edbf eafdg egfadb cbdag | efbdga fgbda dbfag fecgda
+dgb efcgb dcgbe db gecfbd fbgaced agedc gbfeda fdbc egbacf | cgbde dbeacgf afgcebd dbfc
+cde cfbadeg cfgea cdfgb degb ed bfdecg fgced fdceab bgcdfa | afgdbc afgec bgdfca egfdc
+agedfc acfg af gaecd agebdf daf ebdcga dfebc cafde cfgedba | gfac afgc cdbef adbcge
+gfbcae fegad cdfeag degfab bagdf gb debg fcdba fcbdage fgb | fcbda bfdaeg bg bfg
+beafgc gacbde cebdg fcb ebafgdc bfgd fb fegdcb decbf faecd | fdeac fdbg ecdfb ecdbg
+fbgaed dbceg abdefgc gbcedf dbc edcf bgafcd dc gebdf begca | eabcg abceg bedgf acbeg
+cgfbead agc fedga gc dafcg fcgb cfbad gadbce cbfdag bfeacd | gac gcbf fcbg cdgaf
+cbdf dc cebdfg gfdce afedg fgecb gcd edcagbf ebcafg baegcd | cd dgc dc dcbaeg
+adfeg eagcdb fbac fc gcf fgbaec gcefa fcegdb cdefbga bcgea | fgc agcdbe gcfebd bcfa
+aeg febacd ecgdaf cbfag eg dgce dafbge gcfea fgceabd efadc | eg dfcea eacgf gdec
+bfdcge eabdfc geadb efcad afedgc afcebgd gcaf agdef gef fg | dafeg beadg abdfcge efdgbc
+bfc fb afceg efcba gfecda bfga bdeac debfacg egbfca fbgced | geafc cbf bf fgaedc
+ad bcdeg gacebf gafec gcfabde dfcgea bcaedf adc dgaf edgca | ad cda agbfced degbc
+ec bcdfge ebafdgc fbeag cega dabfc fabce bafgce dgfaeb bce | cafgbde cega bgdcfe cgae
+gf bcdfe gdecba fecdg cafgdeb egadbf fge egafdc gcfa eacdg | gf fcdegab fbgdae gfe
+aecfd befg aeb be caebdg fabce cafbg dabfcg bedfcag fcegba | gafbecd cgbfae agdbfc gcfab
+gcedf af fdbcga afcdgeb abecg bafe fagce bdcgea begfca fga | fa bcfaeg bcgead agecb
+cgfeba dgcfbe dfgbe gecd bfgeda cbfgd cfdab cgb gc dgcabfe | fdbca gc edfbag gc
+fgdcae ecafd cd afegd cefba dgfbce cdf gfdeabc cgda fegdba | cbeaf cfd gdfabe deacf
+facgd fbedagc dafceb cadfeg ag fga bedfag fbdgc cega dfcae | cgea cfdga gfa fgadeb
+ecgbfa gcdabf cfbed egdcafb egdfb gd deag bgd gbafe dabfge | egabcf afdbcge fcdbe bcfed
+fbgcde fagebdc fcad gebca cfe aefdgb fdgae fgaced gfaec cf | cfgea cegfa fce dfgea
+dcafbe ead fegcabd begdc cdeba geabdf ae fcgbad acef acdbf | gdbce aed ecafbd bcfda
+cagdeb fea cfabge gfacedb bdfe ef cbdae aecfd fcagd dcfeba | fabedc acgfeb afe dcgfa
+dg cfdabg bcdfa ebcgdaf bfagd bdcg gfaeb eadcfg adbfce fdg | bdcfgae aefcdg fbedac cdafgb
+eagfdb ebcdga bceda fd efdacb cfeda bacgdef dbcf dfe aecgf | bdegfa dceab fed aedcb
+cbfeag dacfbe edfcb adfc fde afdebg begdc df bdcefga eabcf | fagedbc dfca ebcaf cebfga
+ebac eb ebgaf fgdea befcdg dfcagb gfabc dfcbega gbcfea bfe | abec bcgfa feb agcbf
+fgcabde egbcf ga gadfce dbegaf acgd cfedab fdeac egafc agf | afdecb faebgd adfce dabgfe
+fbaecd gedcb cfbea fd gcfaeb cadf cgaedbf def ecfdb efgadb | fcbaedg fbegda fcad baecdf
+bagfc aegcfb fdb gdfc df dcfbga dgabf agecbfd cfbade gaedb | cagfb fbd fdb df
+agcbde fab dcfea gdbf dfbagc cabgfe badgc bf abcfgde bdacf | fdbg dcbga baf dbgf
+baecgd ebfgd cgaed af afdgce dfgae aef debfca afgc cgfbaed | edacbg gceda afe gfdbe
+dcgfe adfbegc cbg bc feadbg bdca afgdb gfcdb facdgb cafebg | dcegf fcgeab bagcdf bcg
+cabgf efcbda ecdafgb gfcdb dc dceg dcf bdefg dbegfc gebadf | bgaedf edgfb efdcbg dfgbe
+dgbca fegdab dgfecb egaf dbafe adbgf bgf bdcefa gf gfcbdea | dfbcea faedbg gfae fbg
+ebadf fbgc egacb cfe fgbcaed aedgcf aebfc dabecg cf ecgbfa | cf fgcbea bdefa ecf
+gbefa ga bfgaed gefbcda bcedfa defab gfa aedcfg cefgb badg | ecgadf gdfeca ecgdaf edfba
+edacg cdgb egacf dg adbceg fbadec gda ebdca bagedcf baefdg | gd bdcea badcfe dga
+debagc gfedac gbdfe efdcg gdfbce bgafdec be bed gbafd cfeb | be becf bcagdfe ecdfga
+dbaeg bf edfgc egdbf fbda bedacgf cgdabe feb faebdg egfacb | gedbf dfacegb edgabfc fb
+feacb afbgdec fcedab dbec cgebaf dbf db dfbea dagcfb fdaeg | eacbf gdeaf bd edbc
+gfaced defgab gaebc cfda cf aefgd cgfdbe caegf defcgab ecf | bcgea acbeg cegba gbeca
+fbced eg gbe gaecdb gcfeb dgef befgcd aecdbf gabcf egabfdc | cefabdg gcfba fdebca bcdfe
+eab abgfed cgbafe fdcgeab bface gcae ae adfcb egfbc gbfcde | geca efcgab cdbaf ae
+bcadg cadgbf adcefb dcgae ced gdeaf gecb cadbge ec bdfgaec | cdagb edgbfca ec cgeb
+df gbacf aegcbd adcbe afdbc fad cbaefd edfb agcdfe gadcfeb | dacbf fbcad dbfac cbagf
+faecdb eabcfg fbgd fdbeacg fbdcge cbdfe cdebg gb agedc gbe | deacg edbcgf fcbgae fbagce
+dfcb faegcd cdgfe ceadgb ebagf bgc fcbeg gcefdab ebcgdf cb | cfegb cb cefdg faecgd
+fgacbde be ceagdb gcefd ceb afgecd fcgeb cfbag dfeb egdbfc | dfaecg eb gbcadef fdbe
+db bedgc gebcda cgeab fecagb aebd ecagbfd dgb dcefg fgbcda | db aegcfb abed gebdc
+faceb edagcf gabefc cfa debaf ac gbca dbgcfe fagbecd ecfbg | gecfadb fecab acdgfe eadcbgf
+gce fgca ecfda gbeda gdfbec agdce afecgd gc acbdfe gbefdca | eacgdf acgf aedcg fcead
+fdega afbge gb abdfcg acfeb gfb edbgfca cbeg acdbfe efcagb | gbaef ecbg gb bdcfag
+bfedgca egfb agcfe bg cagefd dfabcg cgb cbega fgceba cbead | aefgc gcafebd gcafe gbfe
+dbafcg aecfg eacgbf febg fgacdbe afg gf aefbc aegdc cadfeb | efcab bdcgfa bgfe fegadcb
+gbcea dec gfbdce efcbad abdfe fcadbge becad ebdfga dc cfad | bgfecd cebadf gecdafb dfac
+fecdb fagdcb eabcg gf fbg cgfeb bgacde agbcfe eagf bgdfcae | fg agecb dbcfgae cbdfe
+afcbde gbfac fcdgab bgfcae fcdg edgab agbecfd cda dgbca cd | dc acd eafdbc afebgc
+aecdg dgef dcabeg df fdcaeb feagbcd fad fbagc dacgfe fgacd | egdf dgabec gfde bcgfa
+cag gfacdeb cfgdae badge gc aecgd cafegb fgdc fedcba cadfe | acg cag ecadf fbdaec
+agbc fegdcb dbafe cafegd adfcg acdfbg gb gbfda agedbcf gbf | cbag gfb dbfga fdbag
+gadcbe ac bfacged acbf fdcag cad gcdfb afbcdg dgfbec faedg | cgbafd aecbdg fbdcg dbefcag
+dgeba badgecf cgd dbagcf dfgceb cbagef cagfb abdgc dafc cd | fcda gbacf cadf abcdgf
+aecgdf dfabge efcga gced de dafce bdgeafc aed gebacf adbfc | afgbde eda cbeagf fegca
+cg cadbeg dcbef gcedf fcbg gedaf feabdc bgcadef gecbdf dgc | cdg cg fgebdc gc
+fagedb gefbc eagcfdb gcb baefg cefbd acgdbe cg cafg beacgf | bcg ecbfd eafbg fgac
+bfaeg debcfg befca fedgbca fg gbaed cfdabe gfb gbcaef acgf | ecbfa gbf cgaf daebg
+cad egdbacf egcaf aegd dfcega debcfa afgdc cdgbf bcafeg da | dgbfc cafdg gfbcd egda
+agfedb cafegbd fde eagf aefbd gbadfc eadcb fbcgde fe fdgba | fbgda fe befgdc fe
+agdecb gd dbefg debfc geafb gbefca bdg cbegafd gdfa fgdeab | gdebf fdag gfad gcabdfe
+dcegb fecg gfbdec fg gedcab bfdage fgbcd gdabfec dfbca dfg | fg bdgce bfcda aefgdb
+bdceag gdcfe cfedgb ecdfb bc afecbdg ceb facdeg abefd fcbg | dfbae fgedac ecgadb fecdb
+afb cafbeg fcdag dfbe gbdcafe fb ebdgca dcaeb dcaefb dcabf | bf befagc efbadc cbgeaf
+bedagc daeg decabgf gdabfc bgeafc cgabe acd da efbcd abdec | fcedb gade fcagbde bafgdec
+gaced gefdb fc acdbfe bfcgeda gcfa fdc dacgfe debgca fegcd | gcaf fc bacdge cfd
+abfed dcgae edgfbc dcb dacegb abgc ebafdcg aegdcf cb eabcd | dgcae cbaegd cgab eabfd
+eg becg adbeg eafbd befcdag dgabcf bgacd cbdage facedg gae | gceb ge bcge abdfcge
+gdfcbe ea gdfcea cbfed acebf aedbcf gacdbef eabd fgabc fea | adcbgef fegdacb efa abed
+bagced fbaed ebgfca abd ebgfda gdaf cfbegad bdcef da egabf | febga aebfd fabde bad
+fcdeab cdgbaf bed efdagb acfdb ed cdebf becfg gefcbda aedc | edac acde dgfbac dbgafc
+afeg cbgdfe bag cbfgaed fbgdac abcgef cfbge cbega ga dacbe | ceabd fcgeb gaef afbedgc
+bdae dce egdbc adgefc cafbge abegc fgbdc cabedg fabedgc de | gdcbf de baceg ed
+gfdcba cegfa cdbe acgbe gcadeb cba bc edabg gbefda badcgef | bca bgadcf gbdea gbeac
+dfgeb egcfd dabgce afbedc bgd fgaedb bgfa fcbdgea fadbe gb | gfab fdegc fabed cegadb
+dacg ad dgeab efagbcd efbga bgdeca edfbgc bedgc bda dcbeaf | cbeagd dcfbeag beagf gbfecd
+gdce aebgcf adgfc afecg bafdc cdgfea dgf gd bdagfe bdecgfa | bfcedag fdgca bgcaef gdf
+fceba cfebg cea fgbead faebd dabc ecadfgb gdecaf ecdbaf ca | ca dacbef ac dfeacb
+adgceb baeg bde cbgdeaf dbgca gcfdba dgcfe cdebg dfeabc eb | bgcade dbe bgdfcae edcbaf
+ecbafg eg adbefg gfeac ega cdagefb bcgaf gabcdf cbeg aefcd | ecgb cadef cbeg bfgdae
+fedcagb gdcabf cdb dc dgbfe feabc cabdfe fbced abegcf cade | beacdf dcae efacb abcgfd
+daecfb adgbe gcd agcbdf bcdfge ecgf becgd cedfb gc dcaegbf | cg cabgdf gefc fgce
+bdafe dbfacg gdbcf dag ga debacg fcgbed afcg gdfba ebdfacg | aedfb agdfb gdfbc ag
+fbaced fbacd bagced fgba agcbfd gebfdca bg fcdbg dcgef gbd | afegdcb gdb ebcdfa cbegda
+acbfdg gde bdeaf debfcg gbadc cgea degacb eg abedfcg bdeag | agcdb deg edbfgc bdcgef
+cdgabe cd bcfga fbdceag adgef fedbag cfgad cagdfe gcd ecdf | fdec bacgf agfbc gbdcea
+cadgef befgdc be dfabc gecfd cgfabe cefbd bdeg efb dgefcba | efgcd gaefcb cgaefb bgde
+eda fbdacge cfaeg edbcf da adebfg bacgef dcaef fedagc gacd | cdga cagfe da cebfag
+bgefca bdac dec dafec gfebcad acfeb aefdg afbecd cebgdf cd | agdfe cdab bdac agdfe
+bfdgae gfdaecb cgabdf agebdc cbdag gbf gdbfc fb afcb cgedf | fcdbg fbg cfab fegdc
+de fcdbe dceagb bcafd bed cgabef edgf becfg cbefgd gfadcbe | baecgdf edb gbaced ebfcg
+facgebd gedcf aebfcd aegcf egdbcf edf edbcag gbedc df dgfb | gdecb gfbecd geafc dfgce
+bfgac gfcabe fdab afgcbd gfdec eagdfbc eabdgc dgcaf dga ad | da da dgcfa cbgaf
+fdaeb fdaebc fabgd ag fag afedgb dfbcg gdea bcfgae fbcadge | agdfb bedgfa gfa agf
+dc dac fedagb fdcg gfecadb gafed bacged fdeca fabce dcgeaf | gcdf daegcb dc fgdae
+dgba fgcbae gfecabd gedacb dbgec ab dfeca bea dcbfge edcab | baefgcd dcafbge cdbeg abced
+agfcbde bdf fbecdg fdaeb bacd fcdea gbfae db cfeabd efgdca | cabd fbd fgecadb dacb
+bfcda badefc bfgdac gacd fga fdgba ag ceagfdb bcgeaf fgedb | bacfed afg gdcfab febcad
+adcge gebd bfegcad fgcaeb ed facbde fgcda bgdeca dea gaecb | dae dgbe bagcde cbaedfg
+fca gfaedb fecdga bfce bgecaf dcagb cfdebag bagfe cf fgcba | acgbf afcbdge cagfb fc
+caegfdb adecbf cef gdbfec dbgfca abceg afbce dbcaf fade fe | abdegfc fdcegb dafe bcgdfe
+eagfcd afbg bfe cgabfe abgdfec acbef dcabe fb cbgdfe gfaec | ecfba fgab debcgfa bedca
+befdg dgeab aedc ceabfg bda gcadbe cbeag gbacfed da adfbcg | degba gbcea gedfb da
+ebcfd facebg dgafb bdeagf ebcadgf bgadfc fae ea deafb gaed | fea bacfge aegd fcdbag
+fb decagb fbag agfbde ebdaf fdgecb aedbg gdecafb fbd adfce | dbeacfg fdcea fadec bfga
+edbaf bgfcde fd bagef acfd edbcga ebcdfa dfe bfecgda aedbc | fd dfe aedfbc bafgcde
+ecgfb edgcaf badg gaedbc bafcedg cegda decbg bdc cdaebf bd | cedbagf adbg cegfb dbgacef
+cfgdba aebcdgf gaecd bcaed db bacef dba defcag dcbage ebgd | afceb fdagec dgbafc fecba
+bf cabedf bgfae cbaefg bfe bgdaefc gbfc baecg gadfe adbcge | dgebac bcfg bf bcgeadf
+acefbd edcab bgae acg eagdcb bgcadf dfgec cdgae efdcbga ga | dfgacb fcbgda bcade cdfagb
+gdbfc geafdb fdca bdegc cfabgd dfb cagfb cfeagb fd gcdeafb | dcabefg cfagb gfbca fgceba
+bda eagdcb ebdag ba debfgc cabgefd efadg edcbg cebafd gcab | edfgbc bdegc ab ecbfda
+cfa gbface fa gfcbed bfga adecb bgfaced cgaedf becaf cfegb | af agbf ceafb beadc
+cgbed efagcb fdea edbfacg da acdbfe ecafb adc bafcdg bacde | bfcage faed ebadc daef
+fegabd cfgbed ecfba dbagcf gcf gecd cfadgeb cg bfdeg cefgb | gdbeaf dgec edfbg gfc
+dgefa bcadgf gcfdbae eafb baegd egdcaf cbdge bda ab bfagde | ab dgebc bedga beagcdf
+degfabc becgd beac dgefb cfgdba gbdaec dfcgae ec ced cgbda | gcabd bdagc bfceagd gfacdb
+agfebc egbd fgedac dbfca bedgfc fbe dgefc bgdfeac fcdeb be | fbe ebdcgfa egfcdab edfcb
+eabcfgd adc fcedga bfgcd edba cgebfa eacdgb aecgb da dcagb | egfbacd dgcfeab cda cbaged
+dbefc cgade gafc fegadc dfaec egbcda fa dafcgeb afd edfgab | af daf fad fgca
+bdfgc af eacfgb dafgc afde fgdace acf gacfbed aecdg dcgaeb | bafcedg gcfeda afdgc cfgaed
+fbe baefcg abed eadgf efbdga cfgdb fcgbead eb fcgead fegdb | dfacge baed cgfbd ebad
+dgeac bcaed daefcg cgfde dcfbaeg ga fgea bcafdg fcdbge cag | cfegd eabcd ag cgdfe
+fcegb dgeacf acfdeb bfcgda dfbac gd dfg dbga bfgcdae cbgfd | becgf gbcafd gd dg
+gdfec gcadef fec ceagbd ecadgfb gefdb gcead cafd baefcg fc | dafbgce agcfbe gefdb eacgd
+bdcf dgcaef feagdb cdefgb bgced cefgbda bdegf gebca dcg cd | gebac dbgef dcg dc
+cgadfbe fceba acgd bfdgec ga eag gaefdb dfeacg cgfea gcdef | ag agfdeb ga fgdaecb
+gfabd dcaebg afcd fd gdbcaf gabdc gefba bgdefc dfg ecabgdf | gdbafc fd fgd fd
diff --git a/2021/08/second.go b/2021/08/second.go
new file mode 100644
index 0000000..e71c23b
--- /dev/null
+++ b/2021/08/second.go
@@ -0,0 +1,143 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "log"
+ "os"
+ "sort"
+ "strconv"
+ "strings"
+)
+
+func sortStrings(strs []string) {
+ for i, v := range strs {
+ s := strings.Split(v, "")
+ sort.Strings(s)
+ strs[i] = strings.Join(s, "")
+ }
+}
+
+func deduceSix(one string, zns []string) string { // zns == zero, nine and six
+ for _, v := range zns {
+ for _, c := range one {
+ if !strings.Contains(v, string(c)) {
+ return v
+ }
+ }
+ }
+ log.Fatalf("deduce(%+v, %+v) failed!", one, zns)
+ return ""
+}
+
+func deduceTwoThreeFive(ttf []string, topRight, bottomRight byte) (two string, three string, five string) {
+ for _, s := range ttf {
+ if !strings.Contains(s, string(topRight)) {
+ five = s
+ } else if !strings.Contains(s, string(bottomRight)) {
+ two = s
+ } else {
+ three = s
+ }
+ }
+ return
+}
+
+func deduceRight(one, six string) (byte, byte) {
+ if strings.Contains(six, string(one[0])) {
+ return one[1], one[0]
+ } else {
+ return one[0], one[1]
+ }
+}
+
+func deduceBottomLeft(one, two, five string) byte {
+ for _, ch := range two {
+ s := string(ch)
+ if strings.Contains(one, s) || strings.Contains(five, s) {
+ continue
+ }
+ return s[0]
+ }
+ log.Fatalf("deduceBottomLeft(%+v, %+v, %+v) failed!", one, two, five)
+ return 0 // cannot happen
+}
+
+func deduceZeroNine(zsn []string, six string, bottomLeft byte) (zero string, nine string) {
+ for _, s := range zsn {
+ if s == six {
+ continue
+ }
+ if strings.Contains(s, string(bottomLeft)) {
+ zero = s
+ } else {
+ nine = s
+ }
+ }
+ return
+}
+
+func main() {
+ score := 0
+
+ s := bufio.NewScanner(os.Stdin)
+ for s.Scan() {
+ inputs := strings.Split(s.Text(), " | ")
+ hints := strings.Split(inputs[0], " ")
+ outputs := strings.Split(inputs[1], " ")
+ sort.Slice(hints, func(i, j int) bool {
+ return len(hints[i]) < len(hints[j])
+ })
+ sortStrings(hints)
+ sortStrings(outputs)
+
+ // some digits are straightforward :
+ one := hints[0]
+ seven := hints[1]
+ four := hints[2]
+ eight := hints[9]
+
+ // We can deduce number 6 by being in len 6 and missing a component from 1
+ six := deduceSix(one, hints[6:9])
+ // the right segments can be deduced from the one in 1 that is in the 6
+ topRight, bottomRight := deduceRight(one, six)
+ // We can deduce numbers two, three and five from the right segments
+ two, three, five := deduceTwoThreeFive(hints[3:6], topRight, bottomRight)
+ // We can deduce the bottom left segment from 1 2 and 5
+ bottomLeft := deduceBottomLeft(one, two, five)
+ // We can deduce numbers 0 and 9 from the bottom left segment and the fact we already know 6
+ zero, nine := deduceZeroNine(hints[6:9], six, bottomLeft)
+
+ key := make([]byte, 4)
+ for i, s := range outputs {
+ switch s {
+ case zero:
+ key[i] = '0'
+ case one:
+ key[i] = '1'
+ case two:
+ key[i] = '2'
+ case three:
+ key[i] = '3'
+ case four:
+ key[i] = '4'
+ case five:
+ key[i] = '5'
+ case six:
+ key[i] = '6'
+ case seven:
+ key[i] = '7'
+ case eight:
+ key[i] = '8'
+ case nine:
+ key[i] = '9'
+ default:
+ fmt.Println(zero, one, two, three, four, five, six, seven, eight, nine)
+ log.Fatalf("Did not find %+v", s)
+ }
+ }
+ v, _ := strconv.Atoi(string(key))
+ score += v
+ }
+ fmt.Println(score)
+}