feat: Add day 3

This commit is contained in:
Roman Spring 2025-12-03 10:48:30 +01:00
parent 05f5b3e414
commit 7a4cda9669
5 changed files with 281 additions and 11 deletions

63
AdventOfCode2025/Day3.cs Normal file
View file

@ -0,0 +1,63 @@
namespace AdventOfCode2025;
public class Day3 : Solution
{
public override string SolvePart1() =>
InputReader
.ReadLines(3)
.Select(line => line.Select(c => c - '0').ToArray())
.Select(bank => GetLargestJolts(bank))
.Sum()
.ToString();
public override string SolvePart2() =>
InputReader
.ReadLines(3)
.Select(line => line.Select(c => c - '0').ToArray())
.Select(bank => GetLargestJolts(bank, 12))
.Sum()
.ToString();
private static long GetLargestJolts(int[] bank, int numberOfJolts = 2)
{
var total = 0L;
var from = 0;
var to = bank.Length - numberOfJolts;
for (var i = numberOfJolts - 1; i >= 0; i--)
{
var maxIndexI = GetIndexOfMax(bank, from, to);
total += bank[maxIndexI] * (long)Math.Pow(10, i);
from = maxIndexI + 1;
to = bank.Length - i;
}
return total;
}
// private int GetLargestJolts(int[] bank)
// {
// var maxIndex10 = GetIndexOfMax(bank, 0, bank.Length-1);
// var maxIndex1 = GetIndexOfMax(bank, maxIndex10+1, bank.Length);
// var t = bank[maxIndex10] * 10 + bank[maxIndex1];
// return t;
// }
private static int GetIndexOfMax(int[] array, int from, int to)
{
var maxIndex = from;
if (from + 1 > to)
{
return maxIndex;
}
for (var i = from + 1; i <= to; i++)
{
if (array[i] > array[maxIndex])
{
maxIndex = i;
}
}
return maxIndex;
}
}

View file

@ -0,0 +1,4 @@
987654321111111
811111111111119
234234234234278
818181911112111

View file

@ -0,0 +1,200 @@
7383383448669853327488444395431356632533467643668433447312354949444179338343352833433277429334563636
2212122322222322252322212232223221132122212123212332221211222232222221123232122212332222222213222223
1223421222322222212223222231162212333423232222123322223222232232222222232211321223312112222921223222
2274342251334447452432195314423334442326243253434454374212225244643223361286134343534441232331432424
2224214154122121722742282312661132162522221222222222332222222222112292232222211216211222522392822182
2722222122321212422227233526112252222221672221732823142222222222621221224221224223222422223371222125
3236733863343413342493295333932674522923353576553716525432368368455369529465747432351336624353444213
8947645237454249422668322245533349537753255645341252653213278834551222329323873639695562331844222474
8243233333254332424637322332342233243323431244313153253237332325133122313333491122143211333333323143
5433233323822212286262534314832713243246282222382223264234236445833262242123348397933132243623373837
2122222212222323222232221421122222222311232222222212222231232322432322221122212322121222122442314212
7245375342441449443344223413165434435422935225333154453353643442422312261263223758234473646516627453
1122411222223223222222142221211242121226112322122222222211222222212212232222241225111222222312222222
2323272322323322421253526222232137341221223514214633222322622232223352342322521231123232213423642223
2243182233222263413163343462322233336132362332322142532112112433122333222521122322333324222213221222
1562222222234122226234229422262234212212222522321263422654452222621336225753322237122222125311222522
6436237674965757266476664634455565666467746557657656773672267573777674477757663643543774341745677563
3322213244231222221331122373322252133213222322322223122232222342333222332311222133223232222223222223
8467869975578455459766667354465553734767667465546756643567857978174684677638856575156665436755578564
4443333444372636343432432633255243242533424421333223534422422242434242324244334344444833342433344322
3492361313317443243433331244434333443313233251442233333334343241333325822333713523361332253341447522
2282344262563233346436532361272373235423524225335934836233334533511332235326233295633343361536632343
8843765275542538894964544423355343475972488548927459689551495945854334656488563994374755336745282538
2232213225291222222212223224231114232321422222256322122655222242422221442213222622134222533244332354
2634253223122222224562235629364223221232424326131226343222222212221223425233314213323211234144241622
2424317125325422235222222383722225242122132343221225223223312322142222124312133224711452242324322333
4444342433723333333423375474342333334133434523373333338325431533634533444337345433144433264342333333
2222113432211341321312222521422242323312223222312222222243332226232223222122223222422353223131372222
5444554543442434355123347322545453463344222139762522341364554454335253644233546741624534344534424223
2222532221222421242221421141223212222212422222232232211222222152222222245243213224221222411422222221
3426554365123422653444335446252222435262534236413424331455251113741554224523432231332516444243244523
2332253223144224411542452451242343443324443223912225325222242223321224222242423222221624222221245433
5332312493242334252112231222424332223523432542627211336552424243232331222335242316322232233332242229
3538346673333286555779863978348559579323343827557357595787966373333835765538555536959633633342335297
3333334337854242443444433244434444474333873433333334233154438443467424334543413464324434423433423354
2434223425462253421655863243154445355324663435446435343335634233242374634266534224442555632423323365
5512224242226242425222253242225342432513255321322143222253136242555411352122425242252514732342324434
3223221622242212424321144117222212263232823222321262222312122222223113423722211252222222232224224322
8553896465747842968929335823795275579384913477559253367458128187973652278929995332842398223658643433
6565456435445365645554344747544473325553545644356345485566545444445276675466736663545753544955434654
2222275345513133335221222249515322443313233142125235412432434228333324332314526232323525322433335435
4684612848176856344166858738727427447742651222423787212432238166488148663655627383561153657615255579
2922332433133334331223323333213333243312232352394437433332333631322432213333342223322423233423381332
8242242421222322113232321152162222231232223122242212221522231342331222326222524231322623212224223224
3443232334341444323144432354654226343222535532335234234343335433244355444432413233324492558433236433
2414223523454222233223334234222224534214453564515412423442352242221124622443523243233244224232274422
3222142227225324521437222553832313224222215225361237982423379264223222323495123623422144121322274523
4354651174335547555271527114776733773556213153437175475433714635475322645233414731316754123274421489
3332233333321333447373324233434333313232332322343132433432231342322421422313323284324422227123533632
2222223121222314352424232522221242222222522112222431232222322342223122322122323155511113222232223221
6344244554445333744654464374935464543645354434214254442447642667553423624646433456454324373355633454
3122223213223432232232131231142222324333131321231323534354324333421222323113244253324334252322433421
6343567153333224263464163232712623327372735479762432646334583244153326327426327524526317623325171433
5624412243211323226752222222525243222212522242222272221222245821724212182252212213112221226252142232
1212223212224222222213124221232224221352322121122211226212322431222232212324253222715322237222233322
8636569563432254839425735433343737279366734384443863244595374559345446547336564754474811463527274387
3225481728622733232462522435637433334454444433392141413424523446252392553544223443436842334323421233
5443893113242234443636436332132696265445323265834276332473463245224363531463276352962463222326418424
2332321323323134133232313233416225232243123532231323432223333223113332322324333237423325343222121224
2323233224433321282322333321214334522143233223163432322453224423822472332343242222424222323467223432
2554323353134224332323132363333435733344533352331333433243453323433333733333333733333354323433444433
3263455232991332352945337341632187864117659222226642247369322562478346732743643152638365652365685662
8227221322686221486221523636226772334673632722132541923332535232262424822322227276216252165313923782
3575453545345343952774565365733675647432216343825578444595882335966634463568775363447565695483256445
5453312343325322232112433241245252242522422813656333152223333333332534332234414276433732232253529334
5675876644676474788667569884955866686676255866484667634669767637883883498786845686658763547667647656
7246384663414254343654334436616457444434843474673455362343363337746454746396556639344324864644573664
2122222312212123332222162222653233212232122223223223223312122222122243222322122221112235142222232212
2223223364233232221262356335622244223433323326632613242112165232414145232223232632224752363525155232
1242242233223532322322222332231212412222222222234233245122333221523222122112125322225222232222423322
3544435334433533544432523222342733445343422444442443135533233343351444422454244243434455443334223434
4472644625459755454355455545547335543377544334565644445254458535556555654562587376357545535546945554
2322471231432222242224222242123311332213222344122222233314322442493822121222123443221444422122121322
1222521213127232142352221222122231222232323222221322222124332352231212222222232132221231222212225222
7432341446344714532354222355666724269122352422251612432325472132328324445148232323322333825336446424
2263223333422622412522222322712223234242242232321215126321224182214213531332243213234322254223336122
4533933326252522373251631314975626529633433122894219474132616212572217582442854223363514523531249524
4512445245459334343431332574327463641383447742443726345437233746534333543546534641344343544663244655
3855343224543463324822532333525132231342435625374422342233464633365354332233153962263523944383331323
2121221952222512632222343522323325116522121227122122422141212362222322351722221492331266215222161425
1888892624452983959267162696291839222594837275474574256556896714272457626252238577219228248492525251
4444674437213453245443444633644434454454444442485534743444944444244564344343443774441444423443738249
3545354353247355523344523344523353545422352545332433253353435153561354334252332836657323965445352245
5585722655336636324465824616253745562273358432335287512534335221435383537443666347355355756335396453
2243221313211326422223223242322333122221212232222222343332222252323322233132241222313222132212333312
3323233223242414343324321326432334352234333234633465353433541363262434221335322431333323553233273243
2222322223212423222236323222222222222153322232322232231712342323322223212232331232233522322621122432
4313241233324232342233233123323312124313232312322222443231221112322213335223231222342122353422335233
4734443434355354454449443444853434344435455544442434453343424442544545455445242544544445444353444346
8749527774655494555434557462528288554655497655646552486645425533665553545566345546423542523852656835
2523262312234258253231228528324232424188252231221125222254353222232322222223422321222552453222152342
2224321583123522132364132221222127553324382332212225324312223123312211323322731233231333232233134323
3856566548163665556585445655395754456767565257435555557576558859778555674957548655476535955152653455
6423656456385343443153252632425394632422564234693434334638375484335448236336945256253634544745674665
4654422375425545454652353427554222333323324347716435332237355351545355425512457336554522351432424434
6223322123112223864324212341221332723242312212222224212225722222363224223312223142222213432124225224
2332222222122222421222222213222222222222222222322222212223222245122222222341222225242212221222214312
2277564142362345323321544145335632644322442244323454234633327372323332445422344255462354232943453234
2423421243332212322322214222333223231232233314322334334343531243433426333233443476333123473333442413
2523252422222231332113216213311332232233323221313212231327222225221222131252212323222323331312222324
4333335548643437863163334452434222457443364255532447254664436426274462444243235553442543334336375356
4332223434223373253232732242324122222223676524211324132226262346424244332213621827221242414453554246
3233844343534333134333345434346414344447233342356333624443446334343444143332447344233442433353834344
5545225634244572354455335554435654442452273545455252346445554455525414543554435352545515655556452454
6465852584362854687484686676646775656622888865922366595858325387873728264826252437855671877435848648
3321436135326322322222322323553323332372313422342132225313312332134312432222323242131232242424227315
3454582534422421644313643642333244632345353415524343223244556645464643146755541126333544623363721363
2334424233325222323433253352322333313332233335553222232332411251223114464222233325222242225332413434
3333285342343336356322247359236314454439333243824424343463523333343333542344374533233336133333333363
2322222322223132236212532343231212222233225221212222322293222229211323122222223432422323234232123221
2734382233634223234264329332235323454332222551332434322353112431733275227312239123322393322222311324
2132223463213123246626327292347543126654523321427737321721424227228122216122852432362816224225215222
3422313233232432241246323433223321514262313332323344323331334233313322422333433444434323438344322243
1221222721232121242221524213222222222222223221122222222212312214222232112222122222221322222222222222
2118123723433534252822233324234113432275223623322242524551332437334232425327223333213392324232781423
9533622442248224524552589624559733225423333452226314223514222714361212211245223122124235332131132134
9858686597596773748753749799295644989994688889487688987859485846957576965879798984487659967855866867
4123221233414221241134413112332423121332244223222421314424134124224112441344443121144344144431456789
2425546563333434633335365334442357452424443334454435363444636536744433345553423535345625432335543334
8333336245122273351311466233332323125265222262432223424632312293323233243552252371343333132227323135
9466325813422662636836123632226625629366416138256587742328356516756436445453368225764734323475647562
3222312353222722222421222225313662323228822233342223323222321252242273225332621241232244452232212212
2224312251222221242224226234414246252342244241484112742243242222622122243242244222224423132222424243
2333473333332333233252636333563643323335332225335332332231366233331133433333333332524346323332335494
2222121322242231232223228233522322622212122222228212222232212222212212212522223222231221122112222212
3433327233323433343524234353433393384254442813383333733344266133343533433332364323353333733442232525
2224329222224314412232333223422282412341133214222132232243431733232223323323331422214142337224454224
2423234342822232333331233232323223351423324226323516532324213232322122223144294222372733333233333323
4325211433324222522355422341133525326362433333344335243313224312336233356535133234624246553341932333
1492355125222422343361352432445553454656321622923555345253324512125236542226253734445434262522245662
7888654287778298828375337567443824765833447686578546777324879656877542424275491363657844123646377927
3753325535643534565454563435454435423552343635245539543343365553957445232551556355565467435235535553
2313344141213435324222733344222252644528344231423744414772431414623323723427832553424329423344146224
4222232143323212224222314241332323121234221243221223242211122122233223322223342522414122312213222312
4534432236465343454234444212434164323534634431244543243244244534443643364223334534454244333353423554
3465555445446535545553456656666466545656543653565651656555464673565536576575665664557636555256635555
3233632222122221211327222223222112523124121224424222224222222125124321232244223542435322233222252412
1543142332365222162276241257222252112324224622622222242326122266434112324122242412222241262221133323
8785537774546533464755596464136742334457335847426674674167724956236684655656645454334654971329676334
3333239333232233342133323334933333233323333123333323332323233335343232223333434322333313333123433233
6211346184463426766162632636658865266854638442538928827526664536695263283255622456538254512112243466
6437456655364665455765646767663456727475346536547263565536677467666635666555464557475466576673447546
2423451522434224315225222252234552352613223242224221335222526225571225542424223454436234122241343512
5632462313855121211728395462137192731426254126632223131222223962354234222243235256223532222242252335
1224121223322222223312233222322122212231625632434222212132212512222231221222612543535453213123123122
4543441634335562542433343351373375334662254573445344533543433322368333353331432273352523324533323453
3464366216188922122522232225541232251532346722242642331222682366452242426526125124272265221622123521
2123123226237354313262383333446245233132575276231424533672753744227334247132615223324672332325322752
4132363313323614413362322338233323523233463233323331444262336223233263935233326333236333332323313353
5442523632457432448443256342442843344474632344443344344535434351457576436444344384544333422544344358
1624324435515242264412146464522256253356131565332114164614436211511235423365641412631262654436161789
2521235242343432622212224221235472242244233213222123251432322221226331242433322423238229224232222332
2255523123215312442341223222223233452222211122412344524246325237411524412124222582623514224254533222
3513333363343333535342233312234222213433333323333344363222434223833242223331233423325534333362642233
5323122222222132242224222122241222222221431112112122221212212222122112211222122322122222242222252222
5234221351372222242223425213292333522353242255324547264221244252222241221642152215564211631155522342
2322334763232213362544583333573161454223254436563242535525332537661563332333553364376434523423332685
3343333545433347355533424354243433545344345333345235324354654532334555322346523472325445544564432354
3873422198412229257334962342764213825223239762655852295167832735428252263523634362227922722723227733
2242224224222221362322191232335422232122212322232251122261222311223222244242122231221143522212223121
1274225552233222424631332122213132222262333345632332122353322221621154113243514222542212332333222324
4413344246443343373435364443343363443334434442322673233444743244343424234446334344353544343142432442
2434334314543436413434323433334638382443334232334433333423334433343333323333344443343331426334374432
4232112722232222322122222222125212232222122332342114225221222222322231212212222232121322221231222312
2224685155326542657245724242344662215132215527252244642232332162151225255532452222526367163245211265
4435322321237217223312622127422326312332125235322232342751645321223222222114313272223434221437224263
3383462946735843333545234424435733434355532333425433373633333236955522457443334155252323342543273253
4423322414243237412372458534754424342355432254631221446531945784562324813423432558224444263925323435
2257983331255524275142123432222222125557217526141257222662841327593542222122625122552221524226323222
2332222332233333133122233322223233332321734123123263224222333221423323325213219312232213232243132133
2243213352352223222215212452647321122233222312232322223344332542521315121122223321333333222513322122
2112124131223433543232122333238112532223237265122333221232332224313223334412233522433485221122211227
3264346934443442443344644846653444444344644434454374384485484546454443414457346244432834233352363445
2333323223135324248321341323333223243323322334442313323432244333433323243242323312332342222223233323
2443546323334533333448333355464444434353254324434446346444344136146534334344136144444434449325434443
5845576748695549844263995544377877946365842966456376876487475367745694748335988484553439747349887868
1333333423423341331431214232322445333232142222122333222223353232225433543244423331132342233323223332
6733732253853433631532373333273332531223353224535663313323331233514232234352323333333272432726333323
4654482444464445435353355354436457466471356375344463646726453434546464543465383432452434536477646343
1262244453432441545332222641431282252633323634554525352525265522225243353522463254255651243323236223
3343431233453444314235342322554321543427242345335343342433633752323511844374338642323335535345231642
3233233343343353333413323333333233322422443433214333223343333433223333331332333233333233333253422432
2334424436122321233534241323333222124313433322343252242544124122232454435424512452333233223324622341
2322122212232123232122212221322222222222312122223222242223222236221222222222112112242312122623211121
3929427445544565543662984493549759654853543172298446325457696928227427574543693627232663644525186563
3447241444444433245434544534244544625343443346446844313343323448443436445443532634242443245815354433
7373655442586176553867576666656332475566242445653465523176253634326351244535664183334644369343674216
1535132112312315532552555223415214515514145231142323241542534323212225445333313552331211235545546789
3232223254122116217332422215111223113213232261232421118522224121322216822223221543317226222322122214
3222122112321312133133322323224123323233323222122223233233231223222422313325212334232453333732313286
2522245356231855454363177755548967121424222722674529626648142978942918942723972231215542822778529765
3348222313232331111323122833433222233322433323232222223322222212738232123323332342323213232222212332
5426334436424334443213246422223565345662465467234532562343334427554545263526253275564753356565356524
2225222222221322121224222242222323221322221213122342243222223233221222332213213225212242332222122224
6244437443471444553755743243234345443545445474535947842444532454475274421844465564277584477657234457
2232323324122221212342323232341322431323733222421421112322424212433333423333133232343222231224222312
4432255255354411332315512433225254622422523353232343554262215221422234326432634283425453213122212424
2229233322552222332232433323214222322222221731222223214156322522324552225121321322234321236313223322
2514136222242434422426223324213465234223414232333221224224142213242224433242112424641212452344343325
4683635767436242452424473456238223332354252822425224246542632533623378633322454456533344344435532438

View file

@ -33,16 +33,16 @@ internal class Program
}
Console.WriteLine($"{solutionText}");
var startPart1 = DateTime.Now;
var solution1 = solution.SolvePart1();
var endPart1 = DateTime.Now;
var durationPart1 = endPart1 - startPart1;
Console.WriteLine($"\tPart 1 ({durationPart1.TotalMilliseconds} ms): {solution1} ");
SolvePart("Part 1", solution.SolvePart1);
SolvePart("Part 2", solution.SolvePart2);
}
var startPart2 = DateTime.Now;
var solution2 = solution.SolvePart2();
var endPart2 = DateTime.Now;
var durationPart2 = endPart2 - startPart2;
Console.WriteLine($"\tPart 2 ({durationPart2.TotalMilliseconds} ms): {solution2} ");
private static void SolvePart(string part, Func<string> getSolution)
{
var start = DateTime.Now;
var solution = getSolution();
var end = DateTime.Now;
var duration = start - end;
Console.WriteLine($"\t{part} ({duration.TotalMilliseconds} ms): {solution} ");
}
}

3
README.md Normal file
View file

@ -0,0 +1,3 @@
Advent of Code 2025
======================
[Go to Advent of Code](https://adventofcode.com/2025)