feat(2025-03): Add day 3

This commit is contained in:
Josh Creek
2025-12-04 12:42:06 +00:00
parent 7367b9848d
commit 4eaa778adb
3 changed files with 361 additions and 0 deletions
@@ -0,0 +1,200 @@
4732321333332463233337712234322122322247222252423773321362313613333336333732233372323328332333322777
1222244327222414232233422425356322526513215232625252222344534141424312492321632634253122343124442433
5112454424222122431441522442342425334525244254332453524214472412223221252222352512235352425214223422
2222227321754726673633524322456382771445438343537513235332426476332523246251452543731252361447292252
5754818635363378216255676242211353265462243358231497363334444343516236326731322232642636742327379332
3122221222112312312232222262521312223131232212392237234221112213215321242221222223122722223242231132
3332221732222313632231112123312334132423312333223376521312228322222132232231322233613312223323133232
1562433324432523322122322243553245224632262522233262336333252143334323134333211324443413323134412552
4255434822454224334142213155342224334322213323412268213334131242152243542224222242475232221223422322
8678575554446875757776855398756854855887628657665566385684847784545935875964615788576788674444588668
2224132122282231232225222122213512115222212242223112232222423212262221252215213222224122242222522212
6526643435244533412553645532433133432515342223625213345252545334225321221733354423152716334415342425
2422232382217254223228342222122345525213271313333542273324232313233312223721222223231521342942232232
3353245432332434653526334135283437653612538722536244512718328332636432532363993842768352552662374632
4445544245563555645464242235261443573553343522346445663441531676424463555542134364566541335553566255
2121222322122122263322222225421233422333333332456223223233212322332322122141232523222223222321222232
2126212253329254635558385225472857739325164231817544393536578564312324625232214378474322225725423441
2123353122333123714232361322328123442363463333212313343334321323323112331331232312232221382323233232
3131368823833449735734334333323733877433354536323339223583363323933323933413574323326226433337332433
3213333245224323443312343553424939131335233338333333755853423243143431833423315351335433233333333238
7428582265464324456565545476566475834674654524656556444874577644353495333568424145575577567475756448
2222212314222522222251223222232223231532232324232434222222332325232212212522222223223443122222225231
3646777147644343726752461442575516626273263545145133652253626612146272256665626215251253757256421689
3233636544444446365835318437242149432664227534423332724245831254634541356541425386444238663343644568
2626131233311235224362232283232222232341542313121332222222222214464225312332223223227224222213241124
2342232222222214152232222224221223243422223222123232211252232222143232522222425222112324243212522241
5223523122235531212131255451225311211222322212222412225235245252253522222522323232222252222232221342
2434558564634395323523668542166352613356634145635539323652356243365573226645622655241255236423386645
3246323332432323362662243653345212136425361214333333443444355443412724214343632563343444613556623494
4314343313542133234424232223363444223434329532472445124323523421424424547434474243142423322334253224
3243322122223232193522322262412126226212232312422232492211222462622726224216232224122252225412422622
4692122337347366522743247423479136323627444322264583343323279223534151321891338439253232133233833433
4887744333634237235428432147323643363834343345343847584452833344342563333341843436334235334352243433
2422232226272222228223325222211211232122226222227223222228216222236221224222222222222222121222312332
2222233323342314431233322342441322836354133332734424341332333116333812233232322263333233124534333331
5222788637488468742821113311811282485343523432635171658865441165351581662877364375112314214723672789
2222222124312225212223432222112224222232152323212222221112141322252312522222222211342222122241242222
4243114451415313353435125545515144443433434442213544131515142455112345521545453533332354531111136789
5843467592274257353374456452155724325669576246377278276659622845624325436328348833527744563746754641
2222259123512522312214921231532232322232224127522222232242221223223141112183352252232127224125258241
2222422442222472563374132132322215814322223432253628874424241236321232222124112433321321524432322222
2245652224625327454433225415655544657345852466435224342224467632733474524164372452433553453942254444
4422324232524322233344223134262424322233222322134232223322224324232223434212428334124414821212231241
2222332535433222233124211253373332112333233323363323225433223623232322122743242232422123333222233221
3534462525244147242127486635122994794356565942441364344912324464425244344454185354331215423444321944
2326221221622225212222226222112262222244323211215722212231212222222122221231222452224322451242326282
3222222221421222225122242324237212222122323282422222132213323325412262247222312222121221241222255123
6445643428334434684595356662367623443653347433543625323442666484346838263633633336363438455435644646
2222322222322248135241223242122262521212422222142222133221212221234312112421222227122212121512222242
4222435622542233343136345356552656555383542243352546614156425226584625249254563392322415542535343336
8222352522155122244322533331223331222322123124352313342224312223421272542217836112271223642222223335
3333233341223352232324223332243332232223123121332332212362232333323333234341232511326333323224323221
2353835343546235595452382332557432422337443235445273463222355331472354233234423245335424133374533212
7223433159252522833142256916331255245293264212625428522253122924872432311134354342525242492252222242
5232232522252231125122226122233113232231252233223641541631215212343221221632222222231221227311226262
2334342443621356343554443433434444434324364432446252962453464534284533224232223424442464433312447441
2123123222232321231312122331133212323212333133422232213223226222321213214222234322232232333412322532
2282435442242712422433222324332554624422424343424232223241222224426423434434123224423221532323342324
2332833482433244234214424121232337245343323552363444735525331562321232324327435343231362943327532243
3312633453365222213463336413341133223832584333839433322242335242233232233134639236278233733322322413
4434354462644346726443434433444644844454443444434445344434344644377374744424444573442634444464244343
6546655458648617453767556565456556625656765554554553665466564566555665559665663554665656455762776355
4233233243423333353444434333623333332324243232224332332333323333333633326323335324311534223231333334
5555252624567454443851761565335647357555775646243272247675775433533574744267334443452473875513273365
2222322232123222222322222313222312112323331233222242222222223313333321222422222222123342131232312223
4657359479696267347988365896386968946577577344287676553884967398484935768547252598895578378534998364
3455553444441544244545433324444533454347344445545545133255344444534444444445464474444443545374454555
2412222252411424552422341634233532224542252223232322444813278521942123134334424242435333422144423428
2345373524424323423323433433621233344114454253313143343542343333234454312333324133342324223334333323
3566444345435276745556346362675666762452357334758645645334746536388533474337466654353675567764745447
6242668527333662342437226565464123631553211346522724536324734224535622328315462444362344574544275214
3123135233413373132544334333443223241344443343535433433436334233332425352324436333332343533253442343
7384341464429224343613224263436443655675643282324424342445336875233444354494159464431427427883244346
1222241413323777541221232413222528222232224422228126243524312123125221242222412123261232442225355133
6524462231447446648643632477656934236456263447246438663814323367374454583763444536425144324433435446
3675141354533345467429451444221372276463534725169652345373543554414355522329472258628514542752523331
3322113343342347334226333331233322233322223353223333342331332323312334253322331321323243363132432122
3427443236332532433343444434533322233433554264223331431543343343413433349354324333434423332434353135
4234244334238444545314542384544543453444433446544323274325426444445313333544434224523523346453444645
2222322125522322221231117522132222222226262112123152222225313421332316522222522222612711222231232322
4373244343324412211419323233317344233233287433214434133344424937434322143333333444452433343432432443
2243233123232552322232312223221352132412322221222211242232312222223221222332222225332222221222223215
2632939467352846351638133147257252182769228242786372413947911532451365719782232172782952317612327226
2423232448243543241134222422324213524125322212231432323322224333442233145222214331332211245442333234
1222232225272192223322212323242232292212233412232232422133322324222234223243222213122222522423223322
2343721275325233235266362122272322312261333217225252242693262211621233219345326221256917333338332226
3342324323433229332241632532233433412335243133633243433433334345343333332423225423233242332934832733
2142334223312215122122222422332322422225513344221232224214236222224352452225222222322223423265266255
3357423522323354343343443243233345232321243213352323355233244344221243234345455532423634354242523452
3562535624277486333766569865823654572645335888558422374966565756574679546679682782966673368665379376
5455261928432623556643633452545326345552231235554456325323263129263324336453237385244543625313253252
3924243834384546876134323432342635622268337652433544336344375234743636266633437452142822714382734333
3312323223322532233112233232232323212134132431322333323223222234356222121223212221253323422433322333
8652266576356673894668436444857865327564246444765556614249162223855244496683772353778573256418546378
5677577637466886474774758876877687777847786765777787865565568567857767694876656547978786667877768775
5234242233562342263222341622334215244624252125212122262342223423311612312222422232324332152553322232
1132222225431542224412222241224254332141224222222282222212222272224226224213122422221722212413226222
5454445535517545534865344234544656555743454352444454327345344445556245534413354163345475355455454354
5657376536525456473666445653735563237565577785686435474664667557673358634595676376766756355367565446
3123525231632826812432382692321232221161882287193231592316124222612257222422121612227622877312591242
2568786637651743665444476746616777665626777476695467277866858373833778676736555635755166827346364447
3332222221222221232322533221223331232223332123226432221232323222322334224211231322333222223332231323
2412212222242212122122222322222322242221213222222222122146212122422222212232221282223222242332112131
6235735426644856559652142347976635675933592344563394354674467588698523446243925555558754325665477633
3312132332234333222223222242332212223335133211321332233641432343322222223323232242221322113233232324
3444534253513472333445345473444953344514313442555254335355352356556754433364554223424442944534445237
3433644957372433543233332124344323247554341343632345342333523333512433214433345343533543543434734414
4793744343324444432444444443333445243545352443444725344235455443554334244443353543225444536434245545
3937239521428685444227339433953534233141473546642164452472124141322224422325453644542292342548242357
3343323333524333342432333353333313236425333333333333422324342433333333333433233312333433333233332342
3364634363522223545214343425245636536233733554535354544335453364444365354342373646534843536546453344
5675834444647557475535644645343657564564453655556222547734742535457335272566454362566624485654433645
5473331141524543453445534452353743553445436444445472995544544453455444434555465433347554446844474564
3329327624226333643333323439323323333323233133372317324243337333343333713122344753335232832242733233
3112222211232222212222223231212323223941142244211221222112221325232221522222222312222232212331322232
3442344313423435376433465242534624274343135233525322344442243323423345443244452442225443153432233422
4355426635443435534224643447454323742653544653433234445425644335434423333235432534434454352234333351
2422352426524322623552342243141313327452622332223326322553312522313124241326244322261334213453224322
1423242155262225227324262325421623532351233672453522435264264432133442226612233222322362152214824255
3367323434454344934754244344343432444424444444427445447244534545635534442444773444333443453434344742
2221234232222223132214232221123322224222322211323231512133121212222224222312322212522231222322243222
4335373647636343328328313583532423873243867252987923837998452568562352819846868642472346583831337534
3212216232222222233231225212322233234223312222222233222522231221211222122221221223232422252122222221
3343129344535341451549574555642459325862427474432233234448424844829447274255525924261655385214174332
2233322232333333222522324322323133233432122213222223233333432323222323242213243221322236371233424363
3322432123333443232453423343332344333132343333222434323442334341323233343254334533333332425323233332
2222332222123223222432212221921242233121322223213122232232222122221211222324323212223232334223223222
5476943144284333444463363642648385668255456383323343627647368546365463192887464237228341642316352668
3224222222322225221234252322237322222222221222222222222123121231422122312222222213222332222213222122
5252322245521725414445421322423253422153534356314626235163442232613424532253128342133515234123422433
4234323443446346432733442446336544343344335444344334445343444436494444443244442253444447373434333443
2141262224323265112441324216242252521222222225232311323244172424741324342151572122345212412225432121
3412242522323111214224312111332322422241221222522326322212322224122222232322122323212241251372322222
2223132433424343313712271322134426145243224474247562332242923722223222131456522344715232238292212344
4525355533883454455624474543533325545554235557555455444355555532642553333456633345533348564254353455
8336523253324433242262433332246348126252355463933744214343443457247241514444728542364342322384222539
5243328322334341352752235533332222235345533342432466753133413334242535522669342643534134336313346423
7324284323326322224732753123216433825532575393422722222123712553553434278344224226231174222344362359
4333334442342313455254823224422442342535242433247243447824433344222442443334544354244334232323443352
2226222342224223212242323252162241441244321237422342123637423222233223246121262232432323224232513343
2434345354473624553564254535254325353633554245724443572332444114434652534342132541542355331345231335
3323363133333324523321834423473333351332343373333332323339331333333333333352333223424333337332232433
2333241223227232322142231224233321142333333222233332231631324333232332225432313333337221333313343944
4864849444344444463544414454448714234464443442684644248134442464383321554474332445734333263344324453
4375477674324573444535944664444436332634698624458394543647444264433443344343454574816453635344447274
3665421144321123544141351554263654155434561423324244221452634443142146236362451561164554543363156789
2222235242221222124222212212591426323153242321553222255233212232322253317227233322448312522216438314
1632321713222319334425135242222272222112213226227256252242252227316226222516423247112234423232223642
6343265635425336234215526533274434542122553342434444436425442446434354443234368225343453322341544444
1342135221225262312237244341631224122122283223282364425333379422244237726727244323642276243977485216
3373423232555135132533323242373242222314233212283433624359364332234738234423333523435234453223325335
3433234223443634144443344533434452335423334334444423333332624515333333334343434563943244424414335354
3322222221232222334333333325323222343122232242542233223232241422313233433153333434237232322342132321
2222332223322232333224333223121132313221232422222222222212225222232232222243113222612223233332222223
2122142123132233423223312226122232221222422322332222224123244132414143233233122212131122225222222221
3491468222656522466464458427633546486345845858434546264336774542625434433455464868564585466667543447
2232223515136226132332363222122323123213222272233222223322223122173323432152322421231272222222412212
2124422373263172465527332322334272434722223324322423232443222522333514427232361566232214222363425423
4926212326223244133214322625522512234546132442322221132221222212292222122316228311282219224516337422
3172436133532523223323263343223333334343272363334523434632372533333233333334332432332333513452361431
2314333231433353224324233233343333333132355332233425422323323334332233353334332222451223322343322532
2238282342664335323323563343367933332121429282113433373232363254883626333232248323125331333273523263
3535333445243454525444632444543353383443447334413754374525641444244443744754454143453446443335444113
3286642252546522276312261291442323242572612322262622316446281235796361722543226724352667742222153142
3322222222322322232223222212332244122131222142112224221221222222221221122212224122223211112222122221
6536433935656547324435722744153896347628253332444764763653443337232536613957673783698176258557499798
4161243323324331454434436234334252234321534224452231243422424134334452322234342344233234454453244355
2352224822222142322426252252232352482292322213242534352242323332535212223172233222382217223233211222
2344223231232353662352322533442433673553364321354333667252432273344225442235283257253342122331326742
7342854144533266774375361646529354662171236587535533346665633533836753562179777333695275556427457133
1344421124131424224444322443141411414421321333134222212123142323421133234223343112411122223343356789
3223424335333332122221132325332126243326223422232231333313322232165232731335135322231223323232454252
3433355463225785636933551524433444435342353223445454172533484613433343232532334513253466335443322245
5536554877516385564536554167465658566633635644666763545656452444556539389635554556555855585166435565
3335333652134533436333214533343551326544534632345323453432352835543413665513232335565444352333522554
3422223723234342351343712222352622232723262737672627333324243255654333132223322533355434223327227774
3143332124223643541431423431323623433332243334323323324625233312432252423435643544233333343425333344
4221222332231337144225243156445333464313458434544433733333454361714222213543442527232323334122534421
5221222142122222412212214322422222221222411222222222232212222222122116122221212222122412222522222221
2245222247523533241252214434753542963322325363122213431342163161523223334612331423422533226225143443
5735554474649633451276355765346221734216262367474437725274736737384713648348447634743572248325689647
3752551534532564542324553435665753674752753667733343483753723547554345743547567752436345453542633326
1231323243432232173323355425232233652362223323122331255233241325213285322322223952521393335333322224
5671437515421453643424345633946652754634266452436645886533543663665456449717634643462879244371456483
3374374725466446443332533434434332623344443533233489372445343934734744345644733326374375354243834144
6335545576444644365644434663464334845557544546644336633464353535644455446555725444416575666564378445
5325315521327436223375453158334251743323243453636391363443334333343533334435234334524532332693731211
4456548447344384456273344734417544464442414355334565445457544498444243446563464343244244546436543466
2331333353221533423333123123833231313333124432323333323333332322235231164433933323325333333433332253
4334552334217274425228246245622644222346752335842415132523454546524623133246474425242253232424433564
2233344236323465473463223433434332373428433243323243323532333325833232433184222323413342554333363637
2223124225232434223535344324332243332624242142441222254444332234344252556322231244424423444344112242
3547445521453423449433237464344236444224266335375553336636432356753435435444374265744217644363545743
3335333425534633332363212642233557635225334523332656632433635375333523515353334353343132533332643413
2222223222322132324232242213223322223233323122422231433232233323112123242233333241122322222214323353
6999989789859986898999698988899978888978599996857879997869999878799989798999597847657999979799999899
2322122222223312322243223524212436422223222322524322213212222222332522122222222241222122532211223223
2433357222243333342331362234353922351434336324343532422433783335242533533523545423453425231332335273
2223221192222222232211122524435121222222333222432222225131522221211212222211122231221212621222212222
1134811242122424411334442222265224132222242222432232222224432122234121222133252243242322322344232212
+111
View File
@@ -0,0 +1,111 @@
using System.Text;
namespace AOC.Tests.Y2025;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class Day03
{
[SetUp]
public void Setup()
{
realData = File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "Y2025", "Data",
$"{GetThisClassName()}.dat"));
}
protected string GetThisClassName() { return GetType().Name; }
private string[] realData;
[TestCase(@"987654321111111
811111111111119
234234234234278
818181911112111", 357)]
[TestCase(null, 17383)] // The actual answer
public void Part1(string? input, int? expected)
{
// string[] lines = input != null ? new[] { input } : realData;
string[] lines = input != null ? input.Split("\n") : realData;
List<long> maxJoltages = new();
foreach (string line in lines)
{
int[] digits = line
.Select(c => (int)char.GetNumericValue(c))
.ToArray();
// Find the biggest number in the digits array (excluding the last digit), and its position
int biggestDigit = digits[..^1].Max();
int biggestDigitPosition = Array.IndexOf(digits, biggestDigit);
// Ignore any digits before and including the biggest digit, then find the next biggest
digits = digits.Skip(biggestDigitPosition + 1).ToArray();
int nextBiggestDigit = digits.Max();
int maxJoltage = biggestDigit * 10 + nextBiggestDigit;
maxJoltages.Add(maxJoltage);
}
long result = maxJoltages.Sum();
if (expected != null)
{
Assert.That(result, Is.EqualTo(expected.Value));
}
Console.WriteLine($"Part 1: {result}");
}
[TestCase(@"987654321111111
811111111111119
234234234234278
818181911112111", 3121910778619)]
[TestCase(null, 172601598658203)] // The actual answer
public void Part2(string? input, long? expected)
{
//string[] lines = input != null ? new[] { input } : realData;
string[] lines = input != null ? input.Split("\n") : realData;
List<long> maxJoltages = new();
foreach (string line in lines)
{
int[] digits = line
.Select(c => (int)char.GetNumericValue(c))
.ToArray();
List<int> biggestDigits = new();
// Get the 12 biggest digits
for (int i = 0; i < 12; i++)
{
// Find the biggest number in the digits array (excluding the remaining 11-0 digits), and its position
int biggestDigit = digits[..^(11 - i)].Max();
int biggestDigitPosition = Array.IndexOf(digits, biggestDigit);
// Ignore any digits before and including the biggest digit, then find the next biggest
digits = digits.Skip(biggestDigitPosition + 1).ToArray();
biggestDigits.Add(biggestDigit);
}
StringBuilder sb = new();
foreach (int digit in biggestDigits)
{
sb.Append(digit);
}
long maxJoltage = long.Parse(sb.ToString());
maxJoltages.Add(maxJoltage);
}
long result = maxJoltages.Sum();
if (expected != null)
{
Assert.That(result, Is.EqualTo(expected.Value));
}
Console.WriteLine($"Part 2: {result}");
}
}
@@ -0,0 +1,50 @@
--- 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?
--- Part Two ---
The escalator doesn't move. The Elf explains that it probably needs more joltage to overcome the static friction of the system and hits the big red "joltage limit safety override" button. You lose count of the number of times she needs to confirm "yes, I'm sure" and decorate the lobby a bit while you wait.
Now, you need to make the largest joltage by turning on exactly twelve batteries within each bank.
The joltage output for the bank is still the number formed by the digits of the batteries you've turned on; the only difference is that now there will be 12 digits in each bank's joltage output instead of two.
Consider again the example from before:
987654321111111
811111111111119
234234234234278
818181911112111
Now, the joltages are much larger:
In 987654321111111, the largest joltage can be found by turning on everything except some 1s at the end to produce 987654321111.
In the digit sequence 811111111111119, the largest joltage can be found by turning on everything except some 1s, producing 811111111119.
In 234234234234278, the largest joltage can be found by turning on everything except a 2 battery, a 3 battery, and another 2 battery near the start to produce 434234234278.
In 818181911112111, the joltage 888911112111 is produced by turning on everything except some 1s near the front.
The total output joltage is now much larger: 987654321111 + 811111111119 + 434234234278 + 888911112111 = 3121910778619.
What is the new total output joltage?