solution 03-12-2025
This commit is contained in:
@@ -0,0 +1,200 @@
|
||||
5966546654588755548354591946657465889859765969657756889447669666979883895847755487857956955568577855
|
||||
4542746645767855433451537445453466457263428353646434434876784556524857444555654342425558296642647865
|
||||
5422251221224555623173322266326732412226343722532361271223275221532113734725256725254212236227222221
|
||||
2324224426223243523532255245222222132222322212312412227525212622115222222422233212314232235522221282
|
||||
3425335254326242335625565223334643464624361863233224152423533244376533232372522332643344363223232343
|
||||
3323233325233222363224231232322322233232322313334122322327222324232232121323535223223323423333234333
|
||||
2322422254231122221232525212231322423522221222282422162223425222232222652214222222232454212324522222
|
||||
4415447714455363455685537565354363676452954665753777666562457835446656284751447993777546734467675755
|
||||
1321372222222122333322332123323422222322252223222122222332122222322232125211331223132323222331122332
|
||||
2242236323222342222112272221213212334114222323242122132214324232233232222263223222222432432223322122
|
||||
8666442549563855473429495687888487174444636934689888567563752469997857776888435384749968858433947468
|
||||
2324313232246343222224342234422321245212242423323411424213432222224342232332324232413423243423233121
|
||||
2683781715168555587665344823228541542218165425258188531728734552264673257425771487447756633636163149
|
||||
1222223226221322222222223222212222322122125422222222324224424422232223225223281322213534227324222222
|
||||
5453552445153545644522534554544354555623563556577572237374753435463833254947544334526638415427343432
|
||||
3342222252323515234222627222212413112534241272422423223227282252222254242224333544215112522943221225
|
||||
7695333726436944223333723215353562935131693232362577267258343264534326334936632133292734373323684433
|
||||
3232532232532213351332221323343312123432222223162223263333325232221224213321122397232432943333323223
|
||||
2112422344232232513332265243223234713344645443375227325332223332723334345263432322512425374152552325
|
||||
2112223322222265325221122221122322344221322222212222623122162212222222622273252415212543236224282226
|
||||
3522223324214143232445522222552232222425242341322325223221441354225135322232144422223312633322314451
|
||||
3553546964645433646854444545654684586664444554557344656544674454866542455564244724584635864456553552
|
||||
2712132121124212228421333223222232222222232124122134222312221222233132212432223222423223222142222242
|
||||
5243944565445115245394423332345325453227656933441445744435386341486555446252345552545553153155414455
|
||||
5772447636633536424366261954729934453835645363432553634652753366355883885321733333657475668366474567
|
||||
2232222423224213542322311322117222322242124212222212222222224222221311222411142122222233222241221222
|
||||
2172222222222212172122543112232222222221222222244522122321235322221222223222222222222222215222232332
|
||||
3232253411243335242423333323332232433322544313233221242223512322333233223626228323312243113212231323
|
||||
4354444244443444424444454477434344455432453523444454343422334434444643644422433443243433445424346344
|
||||
5654443436244425651246555333445346246614244246522445624445547356466332343845372444136585636453343646
|
||||
2261413264273432522132262224336131112623313612262232223531724262612623213426342123442222222261225132
|
||||
4373423443864444237444325623423232442462514423354435433543444556446334342465349435334635744411243244
|
||||
5422222243422233424421322322425222213133122221222322251421223223211124225122323421322631212321522223
|
||||
5963425243163332355331441641433333326335525213433232232231326234615232642432634222826632333323924451
|
||||
2324222222132312333321322225434334223323234141273322325342323213653322322335412222326323331363123524
|
||||
5333224514863533453264233532582633373331444536362422774345533363335783331322425432393454336733374523
|
||||
6664464844646545643544454444254444265353434444542454344566441844433442436253654434566284334643344434
|
||||
1124522111242222322227222224224221222327222122221212125252251222222252223323221232224522122222321222
|
||||
3333442334343434244343225353423354573442454223433432513444343433243231444354135144434435452344224333
|
||||
2262236237137225321226221221236253135467323313327813423513926312252334262272412611566632233361342242
|
||||
5392592455444746485543643423688666547355365445734465633539744375937844375476945332576556454437338526
|
||||
5332322363334313543655443375335343337333334325233352317335354433136535354333533334332542343322331334
|
||||
2628652623641252526739354945246675138456355651565467436384464627556352765562222374242655131322464255
|
||||
4252232443221482452342244241632224852342234454453297576353341322331334334324427462226124222634324484
|
||||
2343524324251432343246435412256145211311154332123623231522124342233124542142122212433532122132314313
|
||||
3121112232232226342222252124122252313222212223221212212112333422222222321222222222214122222324222121
|
||||
4545155455423544422347654224443555454345452455344535453555555454463645445339625143555465443335555441
|
||||
5232112323357534334442634546523833463236681345253623329255242273527442366224324461232145276286752531
|
||||
2222242544156542442622344421254632325542352232224232645322232332516644243263334234224265151224422625
|
||||
3232111512134223231412251249322622243314221121242521732332241112222322122253222213225222212223133223
|
||||
2137456446344823253847425324457735964736765465454553665529426837274845146672425239823723678622542976
|
||||
3232431332441314142343443324323133323333443343343343433343324433333354331423453433543659333221333543
|
||||
3792349222426221232328521274527712222212236287629895275222522285952122145272182426478113226763322359
|
||||
7232242443222323253213237222232437322224232242342222243173422251162244332422472222162238221422741244
|
||||
3866476683744737663346554542536441642942416535726656534356736771635556445574363637258365544336427341
|
||||
6989475847166863753683472846257524673255552682346416464575366742647387437723554233365788818885437874
|
||||
2321312261931222324262621424212222257228613642222221822242471224242627237377383462243392325323532494
|
||||
5526448865492548412356563325695884355822787558444326673637562977684644265493677563655114625574666445
|
||||
5161451222522622612543222524225232224124243232224273553261338242221526212222523422253426472261572522
|
||||
2234435355325343525422555553333545233523355252232535452333233332545354435452244553547542455323522343
|
||||
3323333333433422433342333423532333383333333333332333433324742333234312334333233333332143332333134323
|
||||
6274624676266423372423166657524747572423742244422172765691253246455536287625642573414593394834966487
|
||||
2492462814355722424462725721442241222555686632111535122622554256225338242262642443624528243355562557
|
||||
2222222322222212212224321132322224223222212122212228212217222124222152332222222122222223311233221223
|
||||
3323222322223232324213223224224212233422222232222422222223324223623231332222333433325223323222312331
|
||||
6843444733422331541526232332253335334454344296626313322444235544444523231322534513484224344543484475
|
||||
3322212221222221222222212122522211122223322212248222122272222222352432112212221214423113223222232422
|
||||
2954465557768644246662646996625779626629677338557847267476472846655567884645856765775586665366284525
|
||||
4144434432182345324664773444643333434322737444536337329324733674332444634343443423531335322454345815
|
||||
6337323722422446423612813562356353443433335371325263243235432566633124336463565756725343331423346356
|
||||
1321467267713441124514622232756371645651116755716557177213236767653267434122662432455424215765442689
|
||||
1352422333742333426333422332143314232133234341322343344334254332332342641423633444522255353235273232
|
||||
5666486465666676663165636645468553453634666665636576548584666696678656766576678645665786669576567765
|
||||
2233233223333342323221423332323332323533363213224334327233323212423121524433523322323332223432227355
|
||||
2332125232123221222222322235232522222324222222222621122532222232341315224223224222223224321321645312
|
||||
3433441344344444354461454433313325643331523224462434323465433523434234354333544342233444423344534634
|
||||
3243223424221322133322434313123353432232134322334224232212233332223432223221334142224124223124342352
|
||||
3321233333533313333343384446574333243333232313443354442362343333333423322453443144333345443232233421
|
||||
5143343533454435554332443333343424355444253453433228343324245435433543333333513434535355233233543355
|
||||
5493355975555767457451576475466757564945655386654644844364595655467684446534246847763251655467536853
|
||||
1422232252222244223314342442214222222212432252222222232142212232211211223312222364443282282422334221
|
||||
2422222142221232333321222231222422212422222222223222222322222121172222222122212211231222222222222213
|
||||
4232332233445435543544132223432323134222223341333133443534421423232422323332332424452132322324343334
|
||||
5333333232555553422337547533354245234652554554545433542552354453343555554315333343544743353447462554
|
||||
8223564221936743763777324425733373415526479287562386241766624787522626327237265478331332285223424926
|
||||
4641336733527335563784257333348885332443483535372331648749334829374337737534666733378445369363327372
|
||||
2537623646443355552263644746464533355345433343357535564354351565545523168233536655546436642352434645
|
||||
2152134125311143243351453321232142342155135343143523135515252121341442514331135454354321433512526789
|
||||
3223133234721443432311332332323252343332222223222233153232253313347332433333333423232222333223231151
|
||||
6572776785737735753946665862896387826755845269998549992857936376966753465489955574499145885395549264
|
||||
3141326224334322222322335353443263223322352235242463222246552324423655422152543223252235211334744288
|
||||
3452233433334233364225523335333335373442233553332656432633136366326453533353333343322745334533354633
|
||||
4453358679558455454455655559433243495345474175545835555345754152535555854455455855355336525874354525
|
||||
2112842221322212341241272227521929124282284244723222422218426224222623222222112169257225162226132221
|
||||
6354323563231433446256927333437365936353452553234357451134663245626563744445354132664332645425713545
|
||||
6442322366534344344123323733265342632232323313935373343333424334233341335335412843344433233244422635
|
||||
3225212222124222222422222323121242222142222222222141122322224222244222222132222212223122221132242242
|
||||
3568364547563266273735644938534578738465559383615775337332835678843357435868448872838933847745336847
|
||||
4565754312212444453434544642553633622423452554362372424752734435485236336275344554436555524244136553
|
||||
6436114624354253213444646233634112136433156435465442232252352226442553541464113336226514346645525789
|
||||
1423311231234334321123424413141224312412313434222242221322433114341324432221211441424443323334456789
|
||||
8552543584793363447722232252568544516923637822434363233257335437727438383533435336322465745452365423
|
||||
3363432162212712133312222223241235211324122222143123222222623222222212713521322242233123234351222731
|
||||
3323443314443353143332413122124243322242323332233333443346243522242323424233134133343225532344433462
|
||||
5354454225434314351546442422332222443456242462336354846647332542333222232421344525245464426323223434
|
||||
2152322321342232222421332222224121221212232223222332323522122231234241422112311122412121112242211322
|
||||
2227145451222236213322564255646212212222224421222223421124123231621222267241322225221122912222262111
|
||||
3546344553226433252323357324365336323524624546454333336735923445345366433787754247453744353353342466
|
||||
4266155222212222131222512122232326222252621428124221122222222261222262454111122452231215221233232222
|
||||
8462466626545326243532255335417443361226666625556926634465451545654312563666643444245586556644463534
|
||||
5235123522251251652235324212242113221157622332255332222512221242221152224251262213225242422126223115
|
||||
2542433334352333335225232234333433352123422324243334333552333233335235324452533452133232235722334333
|
||||
2433343532225534434332235134334323333531334413242341124332334333442333133432333443653223333343333423
|
||||
2222132122233242422242233224232221132422362222221224223241332233554222341122112313135225222122123222
|
||||
2313434442451151114122212333221262442222442144223242232243342242432222233434223222423433441232252544
|
||||
2324243623121264363332236122243226332331672232522733513222321335342553233235433332153233212624623323
|
||||
5635333443333733324334334133322442432413253334354213133334333433343233285345933236327212734353221355
|
||||
2222225422242428332142142234222241362412332523331415224112264523322222212452222422424631322314441143
|
||||
4475657476878685867484639857645948655788668536475657788484657753555949667865645465763786488978775655
|
||||
9848447474667345747435326259288747656536755884544764343644543338453359234332463632566275454636438687
|
||||
6432363437755273265623524444533257237334336234321623235433252366433633255655225756312564253446457442
|
||||
5546856627678773727172469177764592642687586647529895336678557676388743572936655854414676423547775383
|
||||
7162633493716443455872541433245413484313733452444734444443735433449334449544355743436223666644343321
|
||||
2572563533546546653354454645455555474464655365344755454455837555674442464654441346646546564663523445
|
||||
1224322522324224633241324433731212125512121249343714322251226522232461225334521312243332243623222352
|
||||
1352322131221222222232723221222122222232122222223233222222321311234122222122222224222112222223122221
|
||||
3252231432252243451335351534337232434323534236222243234234334323432243435242334347434385222134223375
|
||||
7443335445434424253427657435264354445443444244432347543425337444525314336543354843158465439435434316
|
||||
3222982682222612772861233572624864321221122224223321224722213122286123222313323327132224238422431222
|
||||
3583331732927282422534313323233223335233653324539244123233272535833341233333569473249435233422612333
|
||||
3222322333222112233233221223222122331223121232131233323333323222221332322222222221213221222212214212
|
||||
6353363846364648646668363433543348755462736564266654664453642653554245665434426463444435537354765558
|
||||
3423333221233336431243133223632523221433632333342223243323223324343333432132323344332426313344332342
|
||||
3223322333221132513222232222362312227222735233422222322233233223222223223223232226225233323223223122
|
||||
6553646555554651555648765744544555364165855566558717565344555444356452556585231755555456564479565439
|
||||
4243222422224233113222422222112424162122224121242342222322322123212311442223212214322221222322241324
|
||||
4233211543232214522345423233436232542235243214452245225123332423232243456321244122322222312122323322
|
||||
3345533464734436856864333868255322554635832443937355244434533849338945443344624545452467334964497233
|
||||
3173224222412521239312233219224352422712312214135124322721322122127132219242229418225222714223142229
|
||||
3162432244234745352223325184245322847342714422522321223235843322224286225632528466615689683136253244
|
||||
4235443335446233232464634343733642242443444434214422633443441431321563412352243134322344333553324343
|
||||
3823325334231322342312235313542113322854675333642436345333333232531131233232626343323233333533333532
|
||||
2236143222222523311264442153341623316366132121222421125234232535222325263212221322122122365172122231
|
||||
2434224457335331163122536122434244143142522464253442243472644243571345241145436593432425324332423365
|
||||
2393223335343332233333237234333233212345383133223233323323332235323222321372335352133233838233239423
|
||||
3322854732234455221443232154445442444225411441433343434243234425445345255152343245414242344253335552
|
||||
2232332342424222322222234422361112222222422322252432413233223222242322322211222233222233212312221242
|
||||
4563322912162552292222214622227125363121673551222224137354217832622292422242916312432222811222724552
|
||||
4635352525532364322423332412333463553534533523434455333433353352542335433533443332234247335523433493
|
||||
2294444542133424422422355444452438347432242333213614242435223332422131212345324224323233443833544331
|
||||
4174736724576257235447954142252828447241324247253444226752582818365231137562835462123244353224243232
|
||||
3242227322323232212623222222222132223113336371123243334233232234212122213313232218725322223224232254
|
||||
2133441334322223442352317742724334343433121235333423243331331125224343533332233324231327438334334523
|
||||
3221123111122234331232432532132222223232224322322223223221313422232631312444241232222322311123342222
|
||||
3272222123233224222312222232222212223352121252232221221223423322212222322122324612222222522232442222
|
||||
2311225212524174125221222193462121825412221213612462225273423252722222221272622111324238221191232262
|
||||
2237623172221535335987425563349754836432546631871455984471335427235235532464413722536613447344235432
|
||||
2262423412535112233123337922362144535322434433123322223249332324323423423333524438823224332544254321
|
||||
2222222212222222222322122122222222222232211222231222323122221223222222122222222152112121121122222222
|
||||
1323248243324353637234224642171243534222442341434429323432221228446322212322143373243342291216636342
|
||||
7987579256589679753389663399597634538395537994734689877374477535869584689979667957875566992768596673
|
||||
2652275416222222324126622163122244262281372524225672432226252743252665552521225722236347352467233452
|
||||
2212231222223222432225332112224323141232232222223323221213211222222222222422221222222376226122232215
|
||||
2224222253352211132221241422371214221343729211422222112223222224123222222122112122422233221132324251
|
||||
9344534654223744453425555324553554447523553756365549453243434443352524444554434534342534595552364353
|
||||
4322533534436362432354233246542455564333253354335433326656617455342452366323366355535416243634743223
|
||||
4676645447577676445654544665577775772363446565564575486544444744446745576456554457544455464445455755
|
||||
3322212242324222312533322332313323431323322253323213382253316323222231723232142322223133321222212123
|
||||
2572222122232422221792522242122325212232442424222442222221454523341222122231222227322224327122222623
|
||||
7334447633626359444442545837435676143333574646264533755445555625464676753765324645434643544454464766
|
||||
2322222132232334332233233463313323322322333323334226323333123323233332333333442361223212222322343722
|
||||
2242336244446434444435444534143433444374746464444543443433374435345543347444464474344454444473444434
|
||||
3123322313262231332225222113322234342221233722212322323414433331233442223262212313373332332224234252
|
||||
9352412214242122232222432123422662232322321134242342223323222212232226233212222233121122322222332242
|
||||
4736431626714323842651212533433573342355532543222331333554366272447555533135242642244334645355545545
|
||||
2472223225223243422342419362233325227851222222225242452223222164223324321552243322112524411453122232
|
||||
2252322413521221142342133233231422232424122551252542322222224421121733213592228612333464563262324334
|
||||
2523553215362323542323338155821424424443834352254226529566534556453564333642524272924632627535323515
|
||||
6554345479377685374765446735558667354545646558567463863444555854579473554268452646777677778774564657
|
||||
3232235235333537433236234445553345231333333433332333373152532243352338335343431584424323433351523433
|
||||
1521522241532122522222222521222222222342322111233253322221222522322222232221352231233213214122121251
|
||||
2444223414441453424247563364834454154582463338424436545334355334254634244444523444344844443264385333
|
||||
8484934248686434424347878474937455235484656654643299454444433676573457675578544556428594354533924344
|
||||
2264221112146221123225222222222121212222221213116212225222222122222122251132222165224522228222222222
|
||||
4335444334342436244432332354332753314422524434765543359335522243353625433234235233622335433186522222
|
||||
6774525555567545566345585775465752455561583545555448595552556353555655555455555445653264634545452196
|
||||
8767574132734963847872834724176579773753887822475446995355475274834842122652346537485587595572495594
|
||||
4221222343422545312522321222431243542321254223245125252435324613262223723223252121232422262256166262
|
||||
6334632424242442512232423442441312715342234423462344432423332224422344342234222662314423413134235224
|
||||
2323342323322333323213322223333323111273141111113332435424423223533243132332333432233324232333213114
|
||||
2346135221242136352126332345432632222325132632265232622213272522321222242252345833222539235313123122
|
||||
3383444684433314435473444453291443543434443434868443824343535464233463744433834743433443439814453584
|
||||
2352254744214432641473842923244324222273123342344423232423232322344222331834342253932222622235423241
|
||||
1332314211242422222221322222322112222222221222323223231422223222313212322314222212123221323323312112
|
||||
2232344422342333212212421231222132123222221227224233332232222235222212332452212322232233142534213421
|
||||
6445776542465468544242457727683445544443962648646641476446476776636454444646664864745529576337624474
|
||||
7722122222234222472214222222212422223812223742415321422228423223331323222242346242622222284222221121
|
||||
4531123234334233233248633323343142333332444234332323234434414148453332244343442223152333442433345823
|
||||
2221316224345532222214424621334432622232324326226223222222212342223244232513433522145226533232122623
|
||||
9454527354735656537472876857246747554763445832354347645346455852255465346827664554778667358636366668
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,48 @@
|
||||
use std::fs;
|
||||
|
||||
fn main() {
|
||||
// let input = [
|
||||
// "987654321111111",
|
||||
// "811111111111119",
|
||||
// "234234234234278",
|
||||
// "818181911112111",
|
||||
// ];
|
||||
|
||||
let input: String =
|
||||
fs::read_to_string("input.txt").expect("text file cannot be read to string");
|
||||
let input = input.split("\n");
|
||||
let mut res = 0;
|
||||
|
||||
for el in input {
|
||||
if el == "" {
|
||||
break;
|
||||
}
|
||||
let length = el.chars().count() - 1;
|
||||
let numbers: Vec<u32> = el
|
||||
.chars()
|
||||
.collect::<Vec<_>>()
|
||||
.iter()
|
||||
.map(|c| c.to_digit(10).unwrap())
|
||||
.collect();
|
||||
let first_num = max_number(&numbers, 0, length);
|
||||
let second_num = max_number(&numbers, first_num.1 + 1, length + 1);
|
||||
res += concat_f(first_num.0, second_num.0);
|
||||
}
|
||||
println!("{}", res);
|
||||
}
|
||||
|
||||
fn max_number(numbers: &Vec<u32>, start: usize, end: usize) -> (u32, usize) {
|
||||
let mut max: u32 = numbers[start];
|
||||
let mut max_idx: usize = 0;
|
||||
for i in start..end {
|
||||
if numbers[i] > max {
|
||||
max = numbers[i];
|
||||
max_idx = i;
|
||||
}
|
||||
}
|
||||
(max, max_idx)
|
||||
}
|
||||
|
||||
fn concat_f(a: u32, b: u32) -> u64 {
|
||||
format!("{}{}", a, b).parse().unwrap()
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
# Day 3: Lobby
|
||||
You descend a short staircase, enter the surprisingly vast lobby, and are quickly cleared by the security checkpoint. When you get to the main elevators, however, you discover that each one has a red light above it: they're all offline.
|
||||
|
||||
"Sorry about that," an Elf apologizes as she tinkers with a nearby control panel. "Some kind of electrical surge seems to have fried them. I'll try to get them online soon."
|
||||
|
||||
You explain your need to get further underground. "Well, you could at least take the escalator down to the printing department, not that you'd get much further than that without the elevators working. That is, you could if the escalator weren't also offline."
|
||||
|
||||
"But, don't worry! It's not fried; it just needs power. Maybe you can get it running while I keep working on the elevators."
|
||||
|
||||
There are batteries nearby that can supply emergency power to the escalator for just such an occasion. The batteries are each labeled with their joltage rating, a value from 1 to 9. You make a note of their joltage ratings (your puzzle input). For example:
|
||||
|
||||
987654321111111
|
||||
811111111111119
|
||||
234234234234278
|
||||
818181911112111
|
||||
|
||||
The batteries are arranged into banks; each line of digits in your input corresponds to a single bank of batteries. Within each bank, you need to turn on exactly two batteries; the joltage that the bank produces is equal to the number formed by the digits on the batteries you've turned on. For example, if you have a bank like 12345 and you turn on batteries 2 and 4, the bank would produce 24 jolts. (You cannot rearrange batteries.)
|
||||
|
||||
You'll need to find the largest possible joltage each bank can produce. In the above example:
|
||||
|
||||
- In 987654321111111, you can make the largest joltage possible, 98, by turning on the first two batteries.
|
||||
- In 811111111111119, you can make the largest joltage possible by turning on the batteries labeled 8 and 9, producing 89 jolts.
|
||||
- In 234234234234278, you can make 78 by turning on the last two batteries (marked 7 and 8).
|
||||
- In 818181911112111, the largest joltage you can produce is 92.
|
||||
- The total output joltage is the sum of the maximum joltage from each bank, so in this example, the total output joltage is 98 + 89 + 78 + 92 = 357.
|
||||
|
||||
There are many batteries in front of you. Find the maximum joltage possible from each bank; what is the total output joltage?
|
||||
Reference in New Issue
Block a user