generated from luke-else/AdventOfCodeXXXX
feat: Day 3 is completado
Some checks failed
Continuous integration / Check (push) Successful in 43s
Continuous integration / Test Suite (push) Successful in 46s
Continuous integration / Rustfmt (push) Successful in 31s
Continuous integration / Clippy (push) Failing after 43s
Continuous integration / build (push) Successful in 47s
Some checks failed
Continuous integration / Check (push) Successful in 43s
Continuous integration / Test Suite (push) Successful in 46s
Continuous integration / Rustfmt (push) Successful in 31s
Continuous integration / Clippy (push) Failing after 43s
Continuous integration / build (push) Successful in 47s
This commit is contained in:
200
input/day03
200
input/day03
@@ -0,0 +1,200 @@
|
|||||||
|
6839153353242324143271184245154323237323424572457644344234734233332343344532643622213823683942455442
|
||||||
|
5631465827645468355653355523535772463346671437436425546664765663657756643567465459577656563565556374
|
||||||
|
4955624354245275553534563343424486474572536734881639457526396565533336623535325594536332233523669442
|
||||||
|
3291324213531333233353344365533333223333633237333333235262333435342333233322935388333333323632451366
|
||||||
|
2361252125413211222222271722212171163222222262142572234242222221812226125152522824254523232422226626
|
||||||
|
2242222851522212251212322223224222214232222211122123422321224123322212131322222322222122122223221234
|
||||||
|
3435583152233232362113483433232323223222221225632122533322524253822136332212422335543323322834237233
|
||||||
|
6673575455565253247524653783235758524757774748455354543766533844737527426641417372543366838554544132
|
||||||
|
2443326642366432465233534436662454363365523414737339434242355553356255635313541166924347721541336343
|
||||||
|
3224433333442234422223343434423222323342243423322433245134223324234434133422432343342433324332453321
|
||||||
|
1131421332564525233278522334323232352425525272523413125242343431323512233132467423362232221524232524
|
||||||
|
2235133535333533534535533423532336433435253974437341491332853442255414555354227242253343392122424522
|
||||||
|
3223242633223443223223334132223242232423322313432323422312342342323123532233343251332223432523223232
|
||||||
|
3122322232222353222314123324231532323363223223213323232422633221222322323231333312213233221212222231
|
||||||
|
6332163331714337222836364311273372842454325242242926332212323124221544332324766353516742732331332223
|
||||||
|
6325247434362314443954465443787394433749345636333234355463645426323434755254233228573446463932346183
|
||||||
|
2657525546643354537475363567743455575447869548533564274558455556877456864795223762254762593694455267
|
||||||
|
5646276542234534634464634667412346464476444264643325226263536247454667714465546563752514356545644465
|
||||||
|
8535563347665447677675765755452644362652443563412964856656745628427657354447373354767858527568634773
|
||||||
|
7661646665377544735575762348568664684332165545838664746324633243435136442374574558437553567327676836
|
||||||
|
3433222412243613324322222335332331232613347223352222232242235222222453234242432223143233133223432322
|
||||||
|
3272332365233227243363232273232313334333634433234334273343446333336637364443333633364432321333333813
|
||||||
|
4234634743354355333435434467623342444334534443238656324545656453433433332443524724457664561725453536
|
||||||
|
2222232212132222722242413121434242225122222832222525621555713222232126527222225422442222432221211322
|
||||||
|
2559555386555565556565885558558555554684567535853555545557558555555551354455885555584455445946553455
|
||||||
|
2746111895654354665324782523522228825565226432353356674315642926338674441952295264247247595562665455
|
||||||
|
5466654666654465565764677665555457745658776545655457263634564954555466735564666668764546534552566556
|
||||||
|
5184434222322222322813221242522111232562622352384347523419222526223294243234382431221221222172188244
|
||||||
|
5234335583351154555333333634532354345344543535343535533352333333163255234355353646344246533143422332
|
||||||
|
3212222262322334232122227212662422227122223614221252234343422156312275271532223422336422216222623256
|
||||||
|
7614735674442458447444444743467452846764763787357937745647774786344843663364477464647543726854356777
|
||||||
|
3562436554353533458273272264463223225414634653573432323445375673367535321332262243364584426335124353
|
||||||
|
3485495542323762342383438479593896341315536542465462452948253744248695254464453323432235424524743535
|
||||||
|
1323421326123422442132262333244112112215251523217743234432312255224253235241253254422231321244222222
|
||||||
|
3624533332318523244354443337362332233383312382648326332263312338288867334443333245434232633432323352
|
||||||
|
5795392335543363776356375299488929566551885534657246547623526397562778165827692798876665294262126712
|
||||||
|
4255358344534454433353434435534144545347354434544444424354273564355446256434443362428349644342844537
|
||||||
|
2243222222232222742234234422313332112221315423124222323222124214123143262244223211352122133332124212
|
||||||
|
3455434585345333425443455255562534434243352533476324438353331245343344213354555437245332331443433443
|
||||||
|
5296122233522222171414322443316223423243541222525512221142652322122262222223212526225222142321252242
|
||||||
|
2223242223422452235324142222224423263214444513231223433421231231214444222322313224134243524443321421
|
||||||
|
3536353125625231234368132342312274351331234353343533237233532313273317332112724445353426334233722236
|
||||||
|
2242521522222452222122112126422444224422222223132312222422223126224521423431143222222222223132135221
|
||||||
|
4222462222223221412224422212432422722125176321222422231321285212141221232322224242212812462612222244
|
||||||
|
3333333333242114332333232332235333233222233333333433332333353633333333333233332332333334331462324333
|
||||||
|
2542343412431344564564634534365344346346744434354386274234335424436645512445444225544444442442324345
|
||||||
|
3553343232333422354334323334232343318343322326323514342223142574324233422332343532255334333223412355
|
||||||
|
3433523414432212332332223355324343413344234214333433343113534434324432343314453412343525443426433343
|
||||||
|
6436332335543445237334425336445855445357264343462133755255473613523633357344555783457374233536453433
|
||||||
|
3363373342585434392534467244364386453853442933857233546223533244576646337254745425636254527377463844
|
||||||
|
1113212215241223221152522122421535442422311212233321332321162222323712122215272221221122122222221172
|
||||||
|
9622172422223212124162333331875221222413123222321332252221231212522372763521722634225241222522322725
|
||||||
|
3745763375345348544543466244547449644443443493443349556644543493367344433954483744539434635654378844
|
||||||
|
4463359734937435796394489846456755444937797945454482673756835439458935454757486639877612634644889463
|
||||||
|
3562544854244466554324243665244652441424346456452465544643446445324364364463442653254343652454246566
|
||||||
|
2221227222232133313122522427222223122213222523322221251212222212312212912233213422242522322212812212
|
||||||
|
5737464423366312744324391273443434442933324221536316661334384444333224433324133613317234238237432463
|
||||||
|
3524218255134424232274424343522522323333532428224422232232435232228532442352224222854322332423312222
|
||||||
|
2442456552263254372357625236646786738755547826443975566343472563667616326443466174453232482444666263
|
||||||
|
4224332523334352332321323344245625343132254343355335524425244532342322144245322641323242222221721222
|
||||||
|
2312423322333345325134133532222441325553263252245335222343214444552435243232323323323122225434352323
|
||||||
|
2143243423322521344337243214412543221442712267242244352344542122134427423333313242255233245433463543
|
||||||
|
2511243222224212445222242222822222221222222152212124212221122242332421222212221212635221232124422222
|
||||||
|
3333983424546335524336443313233338763245469595356784336414711324454522345383673455444455728543226633
|
||||||
|
2417444732554745434345253453544566663264347426458733525454334855145434456784444346533443538463575445
|
||||||
|
3333376433425353433321433833333344344333233333332233434465333333443134644334432343333333232333333233
|
||||||
|
3356134422243434273227354226445324351424412143544541425334254221243344512442222511352457132443435362
|
||||||
|
5645351545253844352245465352385855229569652126787456465877551724313542838354452533566365575329541345
|
||||||
|
8727868614256538666237375271771633751411217277651851448667467851246661311241611117421245735613724159
|
||||||
|
3923235452223463265565363332936316435385623636735623533134335366362253123356367452622336482632332632
|
||||||
|
3512153324423245222211544224224214242112212725623524252513222463522722117442245324622324311524225322
|
||||||
|
2333244422234322432153444235174221221122412233514342366336242624233442322455422424126215225322424244
|
||||||
|
6531755564255344135437275754474152192315412314144546534475258644213552535256352423443445434523433554
|
||||||
|
4414243465323433553424534255735346434646434555434355414334354344334424554533344365434644443445522334
|
||||||
|
5665649944574567545356576565664969556562566566639565756648643658779792666555585679767764746655567947
|
||||||
|
2333114324234233143632234235454434252641312332222333533312312533134265523333123342233335243325123333
|
||||||
|
3123332333333323243232433334231333133423253214346322333335324543612323433324331333344222253423213315
|
||||||
|
6667485463377533756566755416466454734484454665575763966653444659844654355364667823455367455459447347
|
||||||
|
2251322232222372222322312222222332133257222422212222213122425262212231272723252292112222422127222222
|
||||||
|
2222221222226232125232222422222212221226532226222122222215223252223222121529412221122322212222242252
|
||||||
|
6556963644257324644344553665435432346847525544636464265556344374425698666454562666244445635546557358
|
||||||
|
1249441333433833343413442434433333321433243414425314324333433453333543423323335231444433344235353343
|
||||||
|
2733674769757586679676576876464777647766655763453887894466618725677565755347786329637821687225686834
|
||||||
|
4542234226212162862227272221624573325422123242424613322541324214434336332222232332227225222149223224
|
||||||
|
5241452125221442522233622222222392322442322322122292232222424321322442242321422224822224522252311224
|
||||||
|
4313223332243123212725222224521361222282232233222242622262442223222124125234212233144334331222212483
|
||||||
|
6865562343235752242245372756416453536554534375346644667345662436226643324445223557445575441535353252
|
||||||
|
2222332221242214221245232221243122242222322122224423133223341412833222222224122252222112231222212232
|
||||||
|
5224926232222313133612137225268322665436432225324522562453233642137262482535263552315122122224233217
|
||||||
|
8386642343244434566655333394336654359234416824464464493353732533644262343398434935186265464463895383
|
||||||
|
3323834443343326433563433554438732633523483233324342655344433433432143926337426257957223437353624634
|
||||||
|
3452576243444334352333542435353557742345444555242453254553655252545342635432343435435343534554435333
|
||||||
|
4231321322223212222221232224232323213333322213122221332423125124221211122321222231222212222212222222
|
||||||
|
5435636767646744952635663524147462634777466656554574653326767543375725574297758523533545371464462352
|
||||||
|
2221211122362226624642222224112321212223623143141112322642413121282221242232311222222222322522226214
|
||||||
|
6537222133646223153423145243232113344232539222232333212352323333324233243222233475533224123283433134
|
||||||
|
4355121612121323636524664456111412513566534136254454135432414454235561316634441411361215341316416789
|
||||||
|
3525344233425634331235372335363544442365333323454454344435423512334334533245343343355535354433453434
|
||||||
|
2223641242234423322244242224132324333223244433344432431223124244274333232113223441423532323122323122
|
||||||
|
7745377586658543475543347353852435427242542651864373773713742724654768236646445343638396923545633257
|
||||||
|
4164725698357735535532433353563332344134366347353394356953563554432333442668446924324728535595734433
|
||||||
|
4334463332444111442244212323322221523433455524123546244344265642431232322316224322142553732434244323
|
||||||
|
2222222422211322222221262222222222232232222222122222222228332122222222222121413221322322213222222272
|
||||||
|
3143412323222211234342232412133522342324234234321433322232332124142134452323426323343453212314422244
|
||||||
|
2321232222152241221252252524242224222233222121322222332222511212212226222213221232232522323221232212
|
||||||
|
2237732556272352233351313211432512113223532311122336112333555221335332525231322253632224321232223122
|
||||||
|
3384356545334345454662634835348641242334344365424432458353344823561448472182584386644444569433553353
|
||||||
|
1354412324325372333133422243222532333252133243332233544331321232413433431235143233444256272232533335
|
||||||
|
9688598577857687868595599557956565587788879794749587969666875589858667986969479979469828965425688477
|
||||||
|
6324223322322222233453331133125342242355222122332323322261232322222225431252123222254432461223113222
|
||||||
|
1452223322222342212671233114123212466422232273212221423223212212226212232421311227122224324311243222
|
||||||
|
4357565354634327753674195735565645445453524654426543552544347334235666762145543555626555553532545555
|
||||||
|
4227223223213322323334363413353334223223225322231352332412313261143362216232222212323222382331333222
|
||||||
|
7435859543595369146744573444494754442549366333393355355343494465444429473393672337444548447829735446
|
||||||
|
2723332333324253634333324133233631532643433562333534423444532641338333733345315235338332762333333331
|
||||||
|
4632549454255945544364842543323353653444336454444556461454593445454254445754446244241454464562494235
|
||||||
|
4212432242242224552233543214624412236242146223224242334243243143322463232231243123434332224331427422
|
||||||
|
2372332332324331235532331234322333433331132464334333332332223323324323362443323229333423333133323332
|
||||||
|
2132222232412222232232213213422132222522112125242233212234322252222234222223122232412532434124232422
|
||||||
|
2322223411252723223122532722581222222215422422422422143414124245322212552222233824622254272225421792
|
||||||
|
5425334236533333634816246356673326373444242345453457374234362645432735459723433345745454751542443125
|
||||||
|
3222433232222232662233722421233322231282213322237232124222522153322222243834532279526282212514898154
|
||||||
|
7745656538777152556524257562765364736454573477647774745517574445766633544573694365674262655166363746
|
||||||
|
6544225256535424355533433354424645455334434545553555455266664527334454765435645456265545326645538354
|
||||||
|
1332224224333223233323332133321223443512323333332233323332323233321332333323243323123343331323224314
|
||||||
|
2846665564433466455446466567445454466464685464565645544266543774646766684654556776655319655447346563
|
||||||
|
4332133413422542534462223434224444324141324532422355243433132342444314325543341234441233643322243245
|
||||||
|
2211227123222211282323221222241222222392232222221276222222273293222222221221411222253222274211242223
|
||||||
|
2223235522663262812322623233323323331262123332322223411322221332322232332232214334332323332332322343
|
||||||
|
3434434434472542423464244443563453444325554444255454434544434614744444474543343445494344347374436363
|
||||||
|
7423323431524522454383237594244554534255236344254452342528145744554442473832427343244323139343457844
|
||||||
|
8392354742477749743654676355458637474444654359969745473812546453943623565919374345826545521427913624
|
||||||
|
2323433224295422832153423127293432323225629713323132142419313412324241232722712365452527222883241122
|
||||||
|
4426226624232525262427213424222912229222725532146222117232226451222644272751454222225564223323212221
|
||||||
|
2622345233352334255222563422421222412236322331366112235632222222252222122225352242123332662421222135
|
||||||
|
2524232423541142542553252523354113355124242222551142225215256642251555542524224213434235553441435513
|
||||||
|
7422438135291133478462358352343133192592232254272798371158143533718936522946321114954262345539683877
|
||||||
|
2322214232522425522264755413516452232244355317735363424342221224232476736655256455453234272464722424
|
||||||
|
2332622164232222426222312216254242336222222123222232212236122352321222223312424262322342226236222212
|
||||||
|
2424428444494623456245632615445277364442236754442752863232543465374443854242222244714334331343244273
|
||||||
|
2522172222225233222232213146222223331232222222123322223732222814223243222232222233222312213222161121
|
||||||
|
1417224167221542222912222262422224126422222212362222912122215262222625282291542272314211344252122122
|
||||||
|
1215253322115761223223224615235658522134225215545223421546227235243122221522252342344211323554222116
|
||||||
|
2223222222612233723331622364233332133242137633582432173513233222122143243522343322324333326323123214
|
||||||
|
4233444334233326424452334432234343344316344233344331633222334333334361463343344342434361323334333433
|
||||||
|
1433412123333324343334533324334333123337344324424326431343463433325421234332335323143434443532534254
|
||||||
|
2322225512212221222222422222322242224123342122322232211222321222222222222251222222243241822224243216
|
||||||
|
3433122234422133111311443323444434221113121212133332213223242342431223213132141112143221244331256789
|
||||||
|
5524338654284266541653482368266555558187573364423812386835545232957323386328778784332838831273688438
|
||||||
|
6626666665455655567648655763756477755736786658574665666344453635666575642567636575546654337455345564
|
||||||
|
2222231224222232212222222222225122122122232322222143322432232253232321521222232214322213522325251222
|
||||||
|
5383645937555372434322645655564258327472548133243341577238534753755336243463337657236534433436243353
|
||||||
|
5254144345532235224234532256143734623642334233614242123632433642223252191532223522121222516312233354
|
||||||
|
2426452274443252333242237217243421242432435263444375344363343534253424813533333435342434244333223445
|
||||||
|
3123322322212232732122232122323234322222223122112133223224245322232331212425323222322522121324212212
|
||||||
|
3863873337668318213334563323484337232838536332344633443453828433732867426265223133584318662238333362
|
||||||
|
2211142214222524356854344445632727533245271633434433423223142228928735163324645532929627452392233342
|
||||||
|
8613623325123324322222343422331652221224245278322422425433463224252423573224232121122222335222422232
|
||||||
|
4323452125442326455546324221543212124114223225535442442522642243455552235343445381245344262365822223
|
||||||
|
6422225632946366344356233748631776253734474864658676935255465551663316255663646936466464543641453333
|
||||||
|
4756744645447455555885575735554655555925567754848457483777547572755547754575645555755524545549446845
|
||||||
|
1343443332254362244344323433234213231331444442322421332422333422324332133324223343244334443243442333
|
||||||
|
2423523435334536243252424311223232442322424223256453543542235434224312442123325223532325444424215224
|
||||||
|
1421229322323322223212626122232621122211114222222321222122222322847122241252312121322233322577112222
|
||||||
|
4333533232223313313353331335326424355322322336343233333292233323333323332232333133333522344332333233
|
||||||
|
2232251523224343217342522242312242325222223132123322232242513343322223232221222212222222442324222334
|
||||||
|
3833333313124144493333359233374332834272237243246557377327263325363116433336332535325354357733233263
|
||||||
|
6333335953334433263443482623544313351664335323532523364224333334335552533412453757924363353335343625
|
||||||
|
3145551425444144134282444324334543245424244222333933341425444333332214544452554324153334154434334314
|
||||||
|
5134151132121454213243115242543341335114121445454444352353354545212254525452523524551142351145146789
|
||||||
|
3324834322124832236465353733592534533233533221132822494369325733332235354559371535222243283233332222
|
||||||
|
1213323131223332324232512332332425373232562233241233252233222445251332211333232723254551322322233221
|
||||||
|
4555535541353543435455455744365544345534123755435445434355445634434546246443662235554454345354535544
|
||||||
|
3433524342424442444445444447432262342365525345234145344313443544344324442524134144322315433155454344
|
||||||
|
2227212543232311232432224221243211122121223432131242131221212214213227623142231343523241221142223211
|
||||||
|
1343437423292263268472343368323325522324523223212243235642221232246336331322372452235236226643223122
|
||||||
|
2152611246253222245323445126652451543546622335266123231535334112122231113524554723255232951335454123
|
||||||
|
2212342232121322212222722223333212422222222221211213222211222322222221222212212222232122233323222232
|
||||||
|
4733454334544442454634444475432344234455454434444343143344646742563444544457475443346442446464345344
|
||||||
|
2233222322432222222212223223212222222236322223323232242523232132223222223212272236232122212366231222
|
||||||
|
3446131413441345332537433443722355342524243143242433422355426323433425354357554333333524252124114321
|
||||||
|
6435744764776554675776786668258745578565977376683866746574635565584466468466747947746667647656668696
|
||||||
|
3562533256723332553421654333544538543552532359345366533822661312573333463564533335315421244323325323
|
||||||
|
4222221322123212221222221134212411172225222221222221272672121232222332522222722113221223222222152327
|
||||||
|
2244223262223356323232422232331212452232222821312221223221334422223323243212213224222424222275722342
|
||||||
|
4453347233333344338353439554341333343573334237252932433333452345293614333528354535453454423344233233
|
||||||
|
6532633235323433255262221452162347233223633562222225312212332523346222332322233352112325333233354226
|
||||||
|
3322222222231123212522273822212221253112352234212221222222242224422223238321224223212215442823225252
|
||||||
|
3223761231135245422223445233222321252522222924252521745716247244232633322252342426622224224228456336
|
||||||
|
4336252431265232675432342214532226422422944624333348317652132252533235863464342242125565223564264372
|
||||||
|
2722334332345245233336254323352243451463352414536642366354222444332437332332333653135424542124112222
|
||||||
|
3542354444344321244433444233334443433423444434233314134355454444344233444423534442354333651334353234
|
||||||
|
6452233323543324351426571162253423133224255427421544423214411353342222143312244573214544443447144353
|
||||||
|
3234314432433233843444324334343432343216358344434544334443344312445333543344433443234337337744242243
|
||||||
|
1162431171642646337471272126664614515277467725431513157173722252553653442346461265365726236366752789
|
||||||
|
7133955774734746587763167284583224325565556553245463633533238656693534448559443546365341565222343363
|
||||||
|
5173568916495736753692865544973635244443543444562644525455248414475444335525534123444534455525266134
|
||||||
|
7742744356336343534426225576532343464463453444363534664243375543444352433634437343262373353243333364
|
||||||
|
4232443424452271624342133224443433733222414335222142244343223542422212421622413524322232211412333224
|
||||||
|
2423222124331122221227222322344212412325322242223332512214322321331242344222241222126153122242224323
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
987654321111111
|
||||||
|
811111111111119
|
||||||
|
234234234234278
|
||||||
|
818181911112111
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
987654321111111
|
||||||
|
811111111111119
|
||||||
|
234234234234278
|
||||||
|
818181911112111
|
||||||
@@ -14,7 +14,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let days: Vec<Box<dyn Solution>> = vec![
|
let days: Vec<Box<dyn Solution>> = vec![
|
||||||
Box::new(day01::Day01 {}),
|
Box::new(day01::Day01 {}),
|
||||||
Box::new(day02::Day02 {}),
|
Box::new(day02::Day02 {}),
|
||||||
// Box::new(day03::Day03 {}),
|
Box::new(day03::Day03 {}),
|
||||||
// Box::new(day04::Day04 {}),
|
// Box::new(day04::Day04 {}),
|
||||||
// Box::new(day05::Day05 {}),
|
// Box::new(day05::Day05 {}),
|
||||||
// Box::new(day06::Day06 {}),
|
// Box::new(day06::Day06 {}),
|
||||||
@@ -64,7 +64,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"Ran AoC 2023 in {}ms",
|
"Ran AoC 2025 in {}ms",
|
||||||
SystemTime::now().duration_since(start_time)?.as_millis()
|
SystemTime::now().duration_since(start_time)?.as_millis()
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -5,16 +5,32 @@ pub struct Day03 {}
|
|||||||
impl Solution for Day03 {
|
impl Solution for Day03 {
|
||||||
fn part1(
|
fn part1(
|
||||||
&self,
|
&self,
|
||||||
_input: &mut Vec<String>,
|
input: &mut Vec<String>,
|
||||||
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
|
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
|
||||||
Ok(Box::new("Ready"))
|
let battery_banks: Vec<Vec<u8>> = self.collect_banks(input);
|
||||||
|
|
||||||
|
let batteries = 2;
|
||||||
|
let mut total: u64 = 0;
|
||||||
|
for bank in battery_banks {
|
||||||
|
total += self.calculate_joltage(batteries, &bank);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Box::new(total))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn part2(
|
fn part2(
|
||||||
&self,
|
&self,
|
||||||
_input: &mut Vec<String>,
|
input: &mut Vec<String>,
|
||||||
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
|
) -> Result<Box<dyn std::fmt::Display>, Box<dyn std::error::Error>> {
|
||||||
Ok(Box::new("Ready"))
|
let battery_banks: Vec<Vec<u8>> = self.collect_banks(input);
|
||||||
|
|
||||||
|
let batteries = 12;
|
||||||
|
let mut total: u64 = 0;
|
||||||
|
for bank in battery_banks {
|
||||||
|
total += self.calculate_joltage(batteries, &bank);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Box::new(total))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_day(&self) -> u8 {
|
fn get_day(&self) -> u8 {
|
||||||
@@ -22,10 +38,73 @@ impl Solution for Day03 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Day03 {}
|
impl Day03 {
|
||||||
|
/// Collect battery banks from input
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `arr` - Vec of strings representing battery banks
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// * `Vec<Vec<u8>>` - Vector of battery banks as vectors of u8s
|
||||||
|
fn collect_banks(&self, arr: &Vec<String>) -> Vec<Vec<u8>> {
|
||||||
|
let mut battery_banks: Vec<Vec<u8>> = vec![];
|
||||||
|
|
||||||
|
// Maps Battery banks into vec of u8s
|
||||||
|
for bank in arr {
|
||||||
|
let n = bank
|
||||||
|
.as_str()
|
||||||
|
.chars()
|
||||||
|
.filter_map(|c| c.to_digit(10))
|
||||||
|
.map(|d| d as u8)
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
battery_banks.push(n);
|
||||||
|
}
|
||||||
|
battery_banks
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Scan a slice of u8s to find the max int,
|
||||||
|
/// (including its location) within the slice
|
||||||
|
fn get_max(&self, arr: &[u8]) -> (u8, usize) {
|
||||||
|
let mut max: u8 = 0;
|
||||||
|
let mut max_idx: usize = 0;
|
||||||
|
for (idx, i) in arr.iter().enumerate() {
|
||||||
|
if *i > max {
|
||||||
|
max = *i;
|
||||||
|
max_idx = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(max, max_idx)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Calculate the joltage given a number of batteries and a bank
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
/// * `num_batteries` - Number of batteries to consider
|
||||||
|
/// * `bank` - Slice of u8s representing the battery bank
|
||||||
|
///
|
||||||
|
/// # Returns
|
||||||
|
/// * `u64` - The calculated joltage
|
||||||
|
fn calculate_joltage(&self, num_batteries: u8, bank: &[u8]) -> u64 {
|
||||||
|
// Find the highest val in the avilable bank slice
|
||||||
|
// leaving enough room for the remaining batteries
|
||||||
|
let (max_val, max_idx) = self.get_max(&bank[0..=(bank.len() - (num_batteries as usize))]);
|
||||||
|
|
||||||
|
// Base case: only one battery left to place
|
||||||
|
if num_batteries == 1 {
|
||||||
|
return max_val as u64;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, place the battery and recurse
|
||||||
|
return (max_val as u64) * 10u64.pow((num_batteries - 1) as u32)
|
||||||
|
+ self.calculate_joltage(num_batteries - 1, &bank[max_idx + 1..bank.len()]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Test from puzzle input
|
/// Test from puzzle input
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
@@ -44,7 +123,7 @@ mod test {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
assert_eq!(answer, "Ready");
|
assert_eq!(answer, "357");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -61,6 +140,6 @@ mod test {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
assert_eq!(answer, "Ready");
|
assert_eq!(answer, "3121910778619");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user