day4: Solve part1

This commit is contained in:
Alexander Kobjolke 2023-12-05 20:36:09 +01:00
parent ea76aecceb
commit c5fee3f585
8 changed files with 228 additions and 152 deletions

140
data/Y2023/D03/actual Normal file
View file

@ -0,0 +1,140 @@
.679.....662....71............................805..........862.680...................................................................687....
............*....-..811..........846..855......*.............*..$........230.92@............................=.....................92........
..........360..........#....664.....=.*...881...677...934.780.......426.*..........8......654.....*959.....539..........21.........*........
.....................+.........*......379..*.........*.........=.........969........*........*.976..............872....*....../....579......
.......566......652...809....482.394......492..303.650..../...38....%...............106...385..................#.....793..484.865...........
......*...........*................*..347.......*.........220.....349...691...392*..................18..797.......................+.........
.....11......890........870.......156............733.................../..........921.....................*......*.............203..........
.............#...238.....*...........................188......294./58........408...............677.......778....104.903............%........
.411+...828.......*.....706.....249..=.....638...848*...........%...............*948............*.....+......+...........917.......817...346
................69.................*..310.*....@..........118*......428=..785...................931...217.....934....475...@.145........*...
...844.885.........#66...........587.......74...773...........194......../.........&107................................%...............375..
......*....826.190.......498........................960............24........212............................398...........474*925...........
...........*...*......../......949.-...213./353.................................@...........853......33*164....+....998...............325...
........640..823....957........&...746..*........*777.............134.......264.......904+..=........................*......./........%.....
....43...............*....457............325..390...........618.........265....*670............=...#165........909..634.......810...........
.....................503.*.....438..904*.............+.........*..563..*............345@......597.........758.*...................*154......
...941...................612...@........691.....&...336.......837..*....489...............................*...462.689....995...106..........
......*383..824...................911........*..467.................44....../.........&445...$...765.647..464.............&..........226....
......................151.....116*........249..................929*.......500..140.........18.......*.........823.....454............*......
..................968..@..........................118*.....300.................*....762.........541......59...*....35....*..........8.......
.....304.........*.......620..@...573.878................................@...@.273.*......572...............661........527.971*.......259...
....*.............83.....%...983.*......*.32..603.....201..............492.166.....339.....*...978$..............373...........340.....*....
.761..758...934..................550.148.................................................25......................*.....*236.............624.
........&......*...393..62*.................167/..716........$........910.767.......380............873*812.362.115..537......48.............
.....#........697..*.......159.....................*.........522..............41.....*.........+............*...........812......13.........
....529.............374......../...%.............................143...........*......109.......365..........952...........*....*...........
...........122*...............555.937......674....................../...529.774..371.................#.38.........../.......304.750....715..
..................873*....819..........165....*..928*345........................*..........77......478..*...440...743...................*...
964...........417.....802..*......230..-....509..................573...........219...675....-.865.......13............25.62*4...980..145....
....*556........&.............278*.................957.....85#.....*................*............=....#.....442........$.......*............
.972.....................541...........91*614..485...............680..792...+........541.325..........486......&..653....#.....247..778.....
.......680.................*.980*710............*...494...............*......88...........................825........#.629.............$....
.399...*......439.........89...........430*....401.....*660....693......407&...........#883....#265......*.....438..........................
........390....*.....388.........21........861............................................................798.-....#........................
..417&.......551.102.$..............332............/804.....463*649..188.........992.....754.203....912..........732.490....................
...................*................*......214.134......................*805.%.....*.....*....*.....#.....*..........*....302.....934..=....
....835.........622..............8...541...*....*..861....442....874..........458...955...985..172.....497.310........341......$....*...644.
....*......246......909....320.............893.150....*.....*....*........717................................................833.178........
...622....*....309.+.........*.........681..........414......612..678....*...........336.................+.....715..........................
...........407.......611.....42...........*159........................................*..97..............355...*..........*954..............
.......967.....120..=...............................................................519....+.....382............974...................651...
739.......*.....*........155.....539................132*.....702......@....923...............905*.........................971...............
....453...149...717.400............*.........618........295.....#..644.......-...786....................*...287...........$.................
...#..................*.............810........*.908$............................*......+........168...903.....*.....&.......@..............
.................306...483..750.108..........570...................934......523..736..#..889......*.........557.......913....107.852..241...
...............................*.......................899............*974..%........42............268...........807..............-...@.....
..958.......610............/......................894.........................242.........300...........$............941..150...............
...........#....131.907.....924...529.267............=.....-./.....692*505...*......265%............$...95.....538........#.................
....137...............$...........*...*.........219.....347..268.............753....................12.....351.................955....875...
......*....258.................854..253...15........................506....#.................559........&................&........*.........
.....376...*.....892.466..160............*.......$................*....*..593.............../............682....721...750..10......187...540
...........866...=..................$...437....994......730....404...703................507...&...........................*....126......@...
....300...............301....@...315.....................*......................572........-...793.......309.518.437..182.310.*.....&.......
...=.....-176.129*........882............................256...............249..*.....+.....................*.....%..+.........71...76..586.
......54..........910............*......734....*..............-.......445.....@.....807.....75.907....477%..................................
.....*........................247.855....%...647.....@.....558...407....#....................%...*................................447..129..
......322..235.......821..............*...........767...............*35..........824.338.55....232...814................546*582.......*.....
..............*........./...........509......270.......-33...673................/.......*..............*......-.....................257.....
....793*831....805.871.....701..........503.....$............%.............710......37..../.........897...-....516.....330...371............
....................*..324*............$............875........293.........*.........@..510..............332..............*..*....2*558.....
.........../......147........373..........%926.........@......-......426...142...............%.......184.........#.....746..................
.......589..755.......285............221+.................$.........*.................571.....539......*.....60...644.............333.......
258....................*.....499............$.107......510.......257..........583.......@...........408.............................*.......
.....................396......*.../..../..493.........................489*380....*........908.711............772..........561......24..559..
.............................548.769.630..........504*........893................605.........*.........*..10................*..653.....*....
........=418..........*576................-..............815.....*.389......481.........*.......859.180....................137..+....275....
..77...........551.901.....535............683.............../.638............./......671.908.....@......360.....611....136..................
...&...........*.......722...........................702.............514............................520.$.........*...&.....$315...#...147..
.......830............*.............#377........39.....%.......384..*.........748..265......271.............885..882...............45...+...
..329.-...........787.311.........................*........115...@..840.........&...*.......*......513..695..........515....................
....*......666...*..............256*999......897.651.......*............457.........34..&...933...*......*......................156.........
..627.......*....24...........@.........................177...22........*...775........668......685...947.....110................*..........
.........172..........295*....540.856..76......................+...337.343.=.............................................18....914..449.....
.............239..........163.........*......770....594.........../..............200.....824*513..........146............*..........-.......
..............#................841...199......=............317..........97.*..........-.............165.....................................
...570...../......................*.......122.......179#..*......138........647......376........65..............735.........................
.....@.221..50..350...@....757.....88........*582.........893.....*.....230.................403...$......................865...927....892...
..........*........#...130..*......................232.........709....&...........105......*..............926=.......966.*.......*...$......
....200...884..............338....*155....822*609....&..84.........935..............#.....481...968.64................+..337.....152...254..
.......*.........203............70......................%...................../................*....*........................627............
.......491........*......321.......$...-.......282............................512.282........564.625........746*825..#..........*361........
...................908...$........335.332.509$....*..../..........216.....-.......*...................617.............896...................
......946...299............657..................255...724..../......*.....830..122..........487.........*.....645.................56.66.....
..984..@...........@....15*.............*858...............150.....91..................498.........654..969.......+............&.....*......
.........104.870.281.........$.......796.......................................................................853.............316..984.....
.........*.....#......=...288.............86......376.804...515...............405..265*................................%....................
.336....152..........671............545.....&......*.....*..............549...*........37.....-....313.#......110.....578..414*.............
..............496.....................*...........536..20........471...*.......397..........437.....*..996...&....18...........200..........
.................=..........308.....147...319.12................*.....465..............$992........71..............@........................
............712.......*123.=..............#.....*629.......%..............................................#..........153..945...........36..
.....+340.....-....850................922...%............812..259*577...#452...-........620.567-.784....985.934.427...@..*.........280......
216............................394......*..589.........-.....................191....622./..........*........*.............124........*......
......764......................*......663...............165...318.....................*....200.83...896..856................................
.....*.......705........751..46...............................-....698....132.......-..81...........................264.....................
...538.......*......170....*..............808........166..........+......$........130........428............852.......*.................902.
..............803...........938..51....66.*...514.......*430..................................*......@..............=............/469.......
.........26@.........90...................473..../..273..............13......656.......242$..829......682...........594...968...............
...180............+.........872..131....................176...781...-.......*.....294.............990.............#..........=.@...../......
....@..344.........184..........*.............................*.........42..153..#.................*.....577......32...........303..334.....
........&..620..................821....172....32.....470....698..........%....................397..301.......................*..........569.
.../........./.........325.@.............*...*.........*........$.....*....+......124...200......*.......827....*861........857.876.........
..808.................*.....581..............644...3..190.607.175..76.712..724.......$........16.358......*...31.......270.........*915.....
...............894...453...............845..........#.......*.....................#......................793..............*...914*..........
..................&......................+...............99.596..597*813...958.831......261*95.....922..........&.......537.......302.414...
...931*.................................................+..........................394......................65.679..........%.........*.....
.......839....644......./262......461...424.....682........................954.............43*.............*.......778..*....464......822...
.............#.......................=..*...........706....289*.....459......*..........-.....234........11..$.......@..373.................
.............../620...536+....100*......907.....159..+.........998.*..........832.....806...........695.....516....................126......
..................................268.............*....893.........12.86.................................................*..................
......+....355.........998..630..............$.....815...*..............*.....168...554...........735............+......861....490..........
.....176...*....513....%....*.................120......568....*314.404+.325..........*..662...855.....495.........467..........*............
..........132......*......677..708.................424.....715.....................520..*..................................36.410...........
..419...........454..............#...730...401&....*.....#............696..............267.=802...................761......*................
............394.........................*........650...637....695......*.....................................586....-...735..154.....423*344
........458..%.....*...728..+..........488.435......................241........795.552.....9.&...............................#..............
...........*....86.981....*..633.........../................762.700.....70*.........../....*.837......-.........20..................%.......
.519...+.652...*........614.......+....................924....*............663..591......192.....952.25.........*....600....#.*239..381.....
...*.366.......845.512......@...200...-....280............*...207............................297...*......828...249.*.....408...............
.189......5........*.....353........245.......#...153..680..............295..50...............+....296.../...........906.............+......
......741*.........466....................710....=.........561*........*..............831............................................909....
...........+.................421............*..........+.......661..103...............................922..752..................431.........
181......218.707....*....273....*..130.$273.980.........656..............517..712..578.......&.524.....@....*.....996..............*....#709
.................442.432..*....64.*......................................../..*....#.......534....*........498.............727.....434......
233*559....................869.....316../..........&.....502..+...884.731.....503................239...499.....94..........*................
........352.......231...................340.....177..584.....922.....*....57...........................*.........*349...222...212&...433.520
...........-.........*981..479..637.....................*969.....*.........=..$.........601...=826...312....................................
..............205.................*../...@.....213.............41.64..........80....889*.............................@....76.=702...........
....353.......*..................114..97.867...*.....542.........................................721...395............816..............*112.
....*.......367.*............478.............42..../..........947.................................*......@......956...........+...883.......
.....870........460............*...................26...........*...........960......212...479....422...........*.......780..595..*.........
....................978*368....921..760=..................416...665..$.........$.381*.......*............933.744....=..*...........792......
....52..........300..........................................*........293.162%........................@...*........259..283.................
......%..........%........119.......575.......#..%......./.748......................945...212&.....595.....248.286...........839..106/......
..940........$...........%............%....880....539.659.............*.........353*.....................=.....*................*.......188.
.....*....254...............794..550...............................701.797............500#................34..475...507..........763........
..649............58..691&.....%............................................386..............@.$44.101.....................997..*............
.........255............................376....732....-..............869......$...........473........*376....220.........@.....721...443....
...........@.913.....168....=909..431......=......@..976.......+.......*..........155............................620.......250......@.......
......806.....*....................*...........@................45.....475...724..*......&45.........+202..-576.....*.........*.............
...............383...........................372..................................474...................................432.471......729....

View file

@ -1,140 +0,0 @@
.679.....662....71............................805..........862.680...................................................................687....
............*....-..811..........846..855......*.............*..$........230.92@............................=.....................92........
..........360..........#....664.....=.*...881...677...934.780.......426.*..........8......654.....*959.....539..........21.........*........
.....................+.........*......379..*.........*.........=.........969........*........*.976..............872....*....../....579......
.......566......652...809....482.394......492..303.650..../...38....%...............106...385..................#.....793..484.865...........
......*...........*................*..347.......*.........220.....349...691...392*..................18..797.......................+.........
.....11......890........870.......156............733.................../..........921.....................*......*.............203..........
.............#...238.....*...........................188......294./58........408...............677.......778....104.903............%........
.411+...828.......*.....706.....249..=.....638...848*...........%...............*948............*.....+......+...........917.......817...346
................69.................*..310.*....@..........118*......428=..785...................931...217.....934....475...@.145........*...
...844.885.........#66...........587.......74...773...........194......../.........&107................................%...............375..
......*....826.190.......498........................960............24........212............................398...........474*925...........
...........*...*......../......949.-...213./353.................................@...........853......33*164....+....998...............325...
........640..823....957........&...746..*........*777.............134.......264.......904+..=........................*......./........%.....
....43...............*....457............325..390...........618.........265....*670............=...#165........909..634.......810...........
.....................503.*.....438..904*.............+.........*..563..*............345@......597.........758.*...................*154......
...941...................612...@........691.....&...336.......837..*....489...............................*...462.689....995...106..........
......*383..824...................911........*..467.................44....../.........&445...$...765.647..464.............&..........226....
......................151.....116*........249..................929*.......500..140.........18.......*.........823.....454............*......
..................968..@..........................118*.....300.................*....762.........541......59...*....35....*..........8.......
.....304.........*.......620..@...573.878................................@...@.273.*......572...............661........527.971*.......259...
....*.............83.....%...983.*......*.32..603.....201..............492.166.....339.....*...978$..............373...........340.....*....
.761..758...934..................550.148.................................................25......................*.....*236.............624.
........&......*...393..62*.................167/..716........$........910.767.......380............873*812.362.115..537......48.............
.....#........697..*.......159.....................*.........522..............41.....*.........+............*...........812......13.........
....529.............374......../...%.............................143...........*......109.......365..........952...........*....*...........
...........122*...............555.937......674....................../...529.774..371.................#.38.........../.......304.750....715..
..................873*....819..........165....*..928*345........................*..........77......478..*...440...743...................*...
964...........417.....802..*......230..-....509..................573...........219...675....-.865.......13............25.62*4...980..145....
....*556........&.............278*.................957.....85#.....*................*............=....#.....442........$.......*............
.972.....................541...........91*614..485...............680..792...+........541.325..........486......&..653....#.....247..778.....
.......680.................*.980*710............*...494...............*......88...........................825........#.629.............$....
.399...*......439.........89...........430*....401.....*660....693......407&...........#883....#265......*.....438..........................
........390....*.....388.........21........861............................................................798.-....#........................
..417&.......551.102.$..............332............/804.....463*649..188.........992.....754.203....912..........732.490....................
...................*................*......214.134......................*805.%.....*.....*....*.....#.....*..........*....302.....934..=....
....835.........622..............8...541...*....*..861....442....874..........458...955...985..172.....497.310........341......$....*...644.
....*......246......909....320.............893.150....*.....*....*........717................................................833.178........
...622....*....309.+.........*.........681..........414......612..678....*...........336.................+.....715..........................
...........407.......611.....42...........*159........................................*..97..............355...*..........*954..............
.......967.....120..=...............................................................519....+.....382............974...................651...
739.......*.....*........155.....539................132*.....702......@....923...............905*.........................971...............
....453...149...717.400............*.........618........295.....#..644.......-...786....................*...287...........$.................
...#..................*.............810........*.908$............................*......+........168...903.....*.....&.......@..............
.................306...483..750.108..........570...................934......523..736..#..889......*.........557.......913....107.852..241...
...............................*.......................899............*974..%........42............268...........807..............-...@.....
..958.......610............/......................894.........................242.........300...........$............941..150...............
...........#....131.907.....924...529.267............=.....-./.....692*505...*......265%............$...95.....538........#.................
....137...............$...........*...*.........219.....347..268.............753....................12.....351.................955....875...
......*....258.................854..253...15........................506....#.................559........&................&........*.........
.....376...*.....892.466..160............*.......$................*....*..593.............../............682....721...750..10......187...540
...........866...=..................$...437....994......730....404...703................507...&...........................*....126......@...
....300...............301....@...315.....................*......................572........-...793.......309.518.437..182.310.*.....&.......
...=.....-176.129*........882............................256...............249..*.....+.....................*.....%..+.........71...76..586.
......54..........910............*......734....*..............-.......445.....@.....807.....75.907....477%..................................
.....*........................247.855....%...647.....@.....558...407....#....................%...*................................447..129..
......322..235.......821..............*...........767...............*35..........824.338.55....232...814................546*582.......*.....
..............*........./...........509......270.......-33...673................/.......*..............*......-.....................257.....
....793*831....805.871.....701..........503.....$............%.............710......37..../.........897...-....516.....330...371............
....................*..324*............$............875........293.........*.........@..510..............332..............*..*....2*558.....
.........../......147........373..........%926.........@......-......426...142...............%.......184.........#.....746..................
.......589..755.......285............221+.................$.........*.................571.....539......*.....60...644.............333.......
258....................*.....499............$.107......510.......257..........583.......@...........408.............................*.......
.....................396......*.../..../..493.........................489*380....*........908.711............772..........561......24..559..
.............................548.769.630..........504*........893................605.........*.........*..10................*..653.....*....
........=418..........*576................-..............815.....*.389......481.........*.......859.180....................137..+....275....
..77...........551.901.....535............683.............../.638............./......671.908.....@......360.....611....136..................
...&...........*.......722...........................702.............514............................520.$.........*...&.....$315...#...147..
.......830............*.............#377........39.....%.......384..*.........748..265......271.............885..882...............45...+...
..329.-...........787.311.........................*........115...@..840.........&...*.......*......513..695..........515....................
....*......666...*..............256*999......897.651.......*............457.........34..&...933...*......*......................156.........
..627.......*....24...........@.........................177...22........*...775........668......685...947.....110................*..........
.........172..........295*....540.856..76......................+...337.343.=.............................................18....914..449.....
.............239..........163.........*......770....594.........../..............200.....824*513..........146............*..........-.......
..............#................841...199......=............317..........97.*..........-.............165.....................................
...570...../......................*.......122.......179#..*......138........647......376........65..............735.........................
.....@.221..50..350...@....757.....88........*582.........893.....*.....230.................403...$......................865...927....892...
..........*........#...130..*......................232.........709....&...........105......*..............926=.......966.*.......*...$......
....200...884..............338....*155....822*609....&..84.........935..............#.....481...968.64................+..337.....152...254..
.......*.........203............70......................%...................../................*....*........................627............
.......491........*......321.......$...-.......282............................512.282........564.625........746*825..#..........*361........
...................908...$........335.332.509$....*..../..........216.....-.......*...................617.............896...................
......946...299............657..................255...724..../......*.....830..122..........487.........*.....645.................56.66.....
..984..@...........@....15*.............*858...............150.....91..................498.........654..969.......+............&.....*......
.........104.870.281.........$.......796.......................................................................853.............316..984.....
.........*.....#......=...288.............86......376.804...515...............405..265*................................%....................
.336....152..........671............545.....&......*.....*..............549...*........37.....-....313.#......110.....578..414*.............
..............496.....................*...........536..20........471...*.......397..........437.....*..996...&....18...........200..........
.................=..........308.....147...319.12................*.....465..............$992........71..............@........................
............712.......*123.=..............#.....*629.......%..............................................#..........153..945...........36..
.....+340.....-....850................922...%............812..259*577...#452...-........620.567-.784....985.934.427...@..*.........280......
216............................394......*..589.........-.....................191....622./..........*........*.............124........*......
......764......................*......663...............165...318.....................*....200.83...896..856................................
.....*.......705........751..46...............................-....698....132.......-..81...........................264.....................
...538.......*......170....*..............808........166..........+......$........130........428............852.......*.................902.
..............803...........938..51....66.*...514.......*430..................................*......@..............=............/469.......
.........26@.........90...................473..../..273..............13......656.......242$..829......682...........594...968...............
...180............+.........872..131....................176...781...-.......*.....294.............990.............#..........=.@...../......
....@..344.........184..........*.............................*.........42..153..#.................*.....577......32...........303..334.....
........&..620..................821....172....32.....470....698..........%....................397..301.......................*..........569.
.../........./.........325.@.............*...*.........*........$.....*....+......124...200......*.......827....*861........857.876.........
..808.................*.....581..............644...3..190.607.175..76.712..724.......$........16.358......*...31.......270.........*915.....
...............894...453...............845..........#.......*.....................#......................793..............*...914*..........
..................&......................+...............99.596..597*813...958.831......261*95.....922..........&.......537.......302.414...
...931*.................................................+..........................394......................65.679..........%.........*.....
.......839....644......./262......461...424.....682........................954.............43*.............*.......778..*....464......822...
.............#.......................=..*...........706....289*.....459......*..........-.....234........11..$.......@..373.................
.............../620...536+....100*......907.....159..+.........998.*..........832.....806...........695.....516....................126......
..................................268.............*....893.........12.86.................................................*..................
......+....355.........998..630..............$.....815...*..............*.....168...554...........735............+......861....490..........
.....176...*....513....%....*.................120......568....*314.404+.325..........*..662...855.....495.........467..........*............
..........132......*......677..708.................424.....715.....................520..*..................................36.410...........
..419...........454..............#...730...401&....*.....#............696..............267.=802...................761......*................
............394.........................*........650...637....695......*.....................................586....-...735..154.....423*344
........458..%.....*...728..+..........488.435......................241........795.552.....9.&...............................#..............
...........*....86.981....*..633.........../................762.700.....70*.........../....*.837......-.........20..................%.......
.519...+.652...*........614.......+....................924....*............663..591......192.....952.25.........*....600....#.*239..381.....
...*.366.......845.512......@...200...-....280............*...207............................297...*......828...249.*.....408...............
.189......5........*.....353........245.......#...153..680..............295..50...............+....296.../...........906.............+......
......741*.........466....................710....=.........561*........*..............831............................................909....
...........+.................421............*..........+.......661..103...............................922..752..................431.........
181......218.707....*....273....*..130.$273.980.........656..............517..712..578.......&.524.....@....*.....996..............*....#709
.................442.432..*....64.*......................................../..*....#.......534....*........498.............727.....434......
233*559....................869.....316../..........&.....502..+...884.731.....503................239...499.....94..........*................
........352.......231...................340.....177..584.....922.....*....57...........................*.........*349...222...212&...433.520
...........-.........*981..479..637.....................*969.....*.........=..$.........601...=826...312....................................
..............205.................*../...@.....213.............41.64..........80....889*.............................@....76.=702...........
....353.......*..................114..97.867...*.....542.........................................721...395............816..............*112.
....*.......367.*............478.............42..../..........947.................................*......@......956...........+...883.......
.....870........460............*...................26...........*...........960......212...479....422...........*.......780..595..*.........
....................978*368....921..760=..................416...665..$.........$.381*.......*............933.744....=..*...........792......
....52..........300..........................................*........293.162%........................@...*........259..283.................
......%..........%........119.......575.......#..%......./.748......................945...212&.....595.....248.286...........839..106/......
..940........$...........%............%....880....539.659.............*.........353*.....................=.....*................*.......188.
.....*....254...............794..550...............................701.797............500#................34..475...507..........763........
..649............58..691&.....%............................................386..............@.$44.101.....................997..*............
.........255............................376....732....-..............869......$...........473........*376....220.........@.....721...443....
...........@.913.....168....=909..431......=......@..976.......+.......*..........155............................620.......250......@.......
......806.....*....................*...........@................45.....475...724..*......&45.........+202..-576.....*.........*.............
...............383...........................372..................................474...................................432.471......729....

1
data/Y2023/D03/riddle Symbolic link
View file

@ -0,0 +1 @@
actual

6
data/Y2023/D04/example Normal file
View file

@ -0,0 +1,6 @@
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11

View file

1
data/Y2023/D04/riddle Symbolic link
View file

@ -0,0 +1 @@
example

View file

@ -28,5 +28,9 @@ handleError :: IOError.IOError -> IO ()
handleError e = do
hPutStrLn stderr $ "I ran into an issue: " <> show e
printResult :: Either Text Solution -> IO ()
printResult (Left e) = putTextLn e
printResult (Right s) = print s
defaultMain :: IO ()
defaultMain = Exception.catch (runAoC Y2023 D03 >>= print) handleError
defaultMain = Exception.catch (runAoC Y2023 D04 >>= printResult) handleError

View file

@ -1,10 +1,8 @@
module AoC.Y2023.D03 where
module AoC.Y2023.D03 (solve) where
import AoC.Riddle
import Data.Array
import Data.Char (isDigit)
import Relude (catMaybes, fromIntegral, readMaybe)
import System.Posix.Internals (const_fd_cloexec)
type Pos = (Int, Int)
type Item = (Pos, Char)
@ -76,18 +74,34 @@ expand arr f pos = ls <> rs
then i : go (move p dt) dt
else []
toPartNumber :: [Item] -> Maybe Integer
toPartNumber = readMaybe . fmap snd
toPartNumber :: [Item] -> Maybe (Pos, Integer)
toPartNumber [] = Nothing
toPartNumber (x@(p, _) : xs) = do
n <- readMaybe . fmap snd $ x : xs
pure (p, n)
part1 :: Puzzle -> Integer
part1 puzzle = sum partNumbers
where
partNumbers = mapMaybe toPartNumber (ordNub (concatMap (fmap (expand puzzle isDigit . fst) . neighbors puzzle . fst) syms))
partNumbers = snd <$> mapMaybe toPartNumber (ordNub (concatMap (fmap (expand puzzle isDigit . fst) . neighbors puzzle . fst) syms))
syms = symbols puzzle
part2 :: Puzzle -> Integer
part2 puzzle = sum ratios
where
ratios = fmap product $ snd <<$>> gears
gears = filter ((== 2) <$> length) $ fmap (ordNub . catMaybes) $ toPartNumber <<$>> fmap (expand puzzle isDigit . fst) . neighbors puzzle . fst <$> gs
gs = gearCandidates puzzle
gearCandidates :: Puzzle -> [Item]
gearCandidates = filter ((== '*') <$> snd) . symbols
solve :: (MonadIO m) => Text -> m (Either Text Solution)
solve input = do
let
puzzle = parse input
p1 = part1 puzzle
pure $ Right [part1 puzzle]
pure $
Right
[ part1 puzzle
, part2 puzzle
]

View file

@ -1,6 +1,56 @@
module AoC.Y2023.D04 (solve) where
module AoC.Y2023.D04 where
import AoC.Parser
import AoC.Riddle
import Text.Megaparsec (sepBy, (<?>))
import Text.Megaparsec.Char (char, space, string)
import Text.Megaparsec.Char.Lexer qualified as L
type Cards = [Int]
data Game = Game
{ winningCards :: Cards
, playedCards :: Cards
}
deriving stock (Show)
-- | parse list of cards
--
-- >>> parseText pCards "5 6 42 23"
-- Right [5,6,42,23]
pCards :: Parser Cards
pCards = L.decimal `sepBy` ws
-- | parse a game
--
-- >>> parseText pGame "Game 1: 5 6 42 23 | 78 56 42"
pGame :: Parser Game
pGame = do
_ <- string "Card "
_ <- L.decimal :: Parser Int
_ <- string ": "
w <- many $ L.decimal <* ws
_ <- string "|"
h <- L.decimal `sepBy` ws
pure $ Game w h
-- sets <- pCards `sepBy` (char '|' >> ws)
-- case sets of
-- [w, h] -> pure $ Game w h
-- _ -> fail "expected two sets of cards"
pPuzzle :: Parser [Game]
pPuzzle = linewise pGame
solve :: (MonadIO m) => Text -> m (Either Text Solution)
solve _ = pure $ Left "not yet implemented"
solve riddle = case parseText pPuzzle riddle of
Right puzzle ->
let
part1 :: Integer
part1 = 42
part2 :: Integer
part2 = part1
in
pure $ Right [part1, part2]
Left e -> pure $ Left e

View file

@ -15,4 +15,4 @@ spec = do
describe "Day 3" do
it "calculates correctly" do
runAoC Y2023 D03 `shouldReturn` Right [528799]
runAoC Y2023 D03 `shouldReturn` Right [528799, 84907174]