Skip to content
2,000 changes: 1,000 additions & 1,000 deletions 2024/ts/day-01/input.txt

Large diffs are not rendered by default.

1,996 changes: 998 additions & 998 deletions 2024/ts/day-02/input.txt

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions 2024/ts/day-03/input.txt

Large diffs are not rendered by default.

280 changes: 140 additions & 140 deletions 2024/ts/day-04/input.txt

Large diffs are not rendered by default.

2,672 changes: 1,334 additions & 1,338 deletions 2024/ts/day-05/input.txt

Large diffs are not rendered by default.

260 changes: 130 additions & 130 deletions 2024/ts/day-06/input.txt

Large diffs are not rendered by default.

1,700 changes: 850 additions & 850 deletions 2024/ts/day-07/input.txt

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions 2024/ts/day-08/input.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
.........................p........................
......................h....C............M.........
..............................p....U..............
..5..................p............................
..6z...........................................C..
...............c...........zV.....................
...5.....c........................................
.Z.............h........S...z....9................
.O............................9...z........M..C...
..O....5..............................F..M..C.....
..Z.........5.c...............M....V..............
........ZO................q.......................
s...O................h..Uq.....7V...........4.....
.q.g..............c.............p.......4.........
............hZ.............................4G.....
6s...........................U.Q.....3............
.......6.................9.......Q.............3..
....s..D.........................6................
.............................................FL...
..................................................
..g...D.........q.....f.......Q...F....L......7...
...............2.........f.............V.L...4....
...................2.s...................f3......G
....g...........................v......7P.........
..2..g.............d.....v...........P.......1....
..............u.........f.............L........G..
.........l.D....u...............d........o..P.....
..................8...............9..1......o...7.
............l.....................................
...................l...S...........F.......o..U...
.......................u...S......................
..........l....u...............m...........P....G.
......................................1.8.......o.
..................................................
..................v.......S................0......
.............v........d.....1.....................
..................................................
..........D....................................0..
...................m.............H..........0.....
...................................d......0.......
..................................................
....Q.............................................
................................H.................
........................H....................8....
..................................................
..................................................
.........................................8........
.......................H3.........................
............................m.....................
................................m.................
.............O.....E...M.................S........
....................................S.........D...
......u......................................V....
................u.E......M..............V.........
...e...............................a..............
.................v..........a6....................
...............ue...............6...............V.
..........e..E..........M......................V..
............................M.............F.a.....
.............................a..........i.........
....................n.............A......F........
.......e............N.........6...........m.......
........v..............D.....i....................
........A.v......D...........................F....
...................v..........S....q.......m......
................n.......2......m..................
.I..................2...C.....i...............f...
.....................2.S.........i................
........k...0.....................................
......I..........k.......................1........
..............D....k..N....1......................
.....A.................n..C.......................
...........................2..1........fm....A....
.....I........k...7............................f..
....I..........n.........N...d...C................
.............z...................W................
...Z.................................W.........y..
............z....w.....................5..........
.................z....d...4......Q.U......5.......
....................d...........F.......fC.U......
...................w........................U.....
.............8......w..N..................U.......
.7.................4...3.............5............
...............3.......s..1.54..........W.........
.........0Z.....w.............................c...
.Z...................................o............
................z....8...........K......Q.9....c..
............P.........4dY...s9...........O..p....u
.....................s..........o...............W.
....................3.......................O.....
........................s..............p......O...
...................c.............P..9..K.....p....
................Y....P3.....7..9..................
..................8.......o...........K...c.......
.......Y........8.................................
....Z7.....................y.q......Q.............
..............................y...................
......0.....................y..................Q..
....................P6............qo......p.......
......................................q...........
2 changes: 1 addition & 1 deletion 2024/ts/day-09/input.txt

Large diffs are not rendered by default.

118 changes: 60 additions & 58 deletions 2024/ts/day-10/input.txt
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
5678970120787667809876787651450321789810165432234561012345
4301787431296556912765698540341410786728765501103676545434
3212896594365443213454501231232545695439154610898387656946
4307885785872337801653215432545694321089043781763296047877
5456934576901236998740126721694787899676112891054102137898
4327825676210365485035432830780146788765208982567873223703
1012010789301345304126701910567235623654367643432984012612
9887652105401253213239878323458945514545106543221265698543
6798943766798760560145569850179876408763215456100896787432
5212237854899621056776457763287654309854580367018701656501
4302108983014552345889308954390101218345691278929632540987
8921321212123467496973217654321010101210782987834541231236
7010450908765658787210106563898110567623458906543210340145
6524567849434349872323293478967223408988967217890107459054
5433008956721238721494782566554310510177654394345498768765
8942112349810101430585691057431214321287656783216321659056
9853523658901233549674541008120109450392345654307010123141
6765434567890312678234432219078218765431874309458927034230
1034323450765403510165498348569341016210967218567898985541
4125614321877654523276327653414452547893458967898769876632
3210701234988347678987014512103963458982105450745601896781
4678890215679298689898101105432878967821123301234312765890
5469810309100198776543239416001263456710054210126543454323
6954323458210789743987678327122452349821269329237632670110
7856542167345679812310565498214301265430178778748911789224
3067630018901256701423457012303210178923476565652100654343
2188921078872345690501298989452121089012383418983434334534
3298934569863418987632367898763011298234592307894521025676
0387650101678507876753456501014980347105681016765601210787
1456343212589216909865401432325671256501789823454782309898
2341067823410365419872316543234560787432328987123495434321
8932058934321474321891027652101765698543212656016596521030
7634149965430589890765438984989854321692303443067787676543
4543232876787672763210567823870143430781054512198971980612
4687601045298101454569498014561034231278766503456890121701
3894523432101212343278307601432120140389107652107765439890
2183410589043239852101212587347899655473298940998987610141
1012398679650126760120103496256978796554567831876898543234
0310487778743245679833210145107878987143278722365687650125
1223456899012632988744103230123217610012189013451232105676
8346543456598701279655654389874306526323076567600345694789
9857812347405654210346969210165435435414105458912256783238
6768901098312343981237878301456521056905912345863109890104
0345650101232107834369765412347678167876801056874223454323
1278761321943456125078098943678999101210760767985214567910
2109874430854534076165107834567783212323458898876307698876
3436543561763325689234256623478654323212789954343298714565
4567612675610118763240345510569823434101652765210134503443
5698203984323709454121245432234712345612501897898325612652
6782100112345890365039876101165601016780432101107210726761
6783078201076761276321276543036523239891569232216874835890
5894569345987457889430389236543210145652678740125965934701
6784578896590356996321298107012301276743245656734014821012
5693678787101243987654301058905434985890130543876523498763
4542109843262012276019012765676125673981021982923434549854
3432101257876540145328943894387089012832123671019323676345
4309210369901234239457654703298976326721034501208710789234
3218765478710123378765645612107845435434345212345621678101
432109865210212123765432101234321098543289654320132112121058
045678774324301012892343023445456787650198763013241001034569
187678789465692321001056014896234986456787012894653212123678
296589921056789433217837895687145675323891233765784589238987
345437835434576544786921278761010014210710321212098676521067
032126546323465435695430789760121223121653450303145125430678
123010567810156543212345699859834321056544067654236012321589
543213498987657665401030787348765430187432198765987622345432
654100332394348972342321895201256589196343089543212331056741
789011241003238981089400776100343678015434567630105449879870
296721256210169895676510385011892349101325678921256756768987
129830787323456765410321294332761058210012310123890891057610
056745698234556786329454301245656567341110567894781232346521
145894510149645699438765892398305678956923498965654343765430
236586789838732388454326765567214307967845697874505652894321
105675676545321267565810674354303212875430786543216701678912
234321501656130054278989983289432120123421803403545810787600
321030432567032123123678100176563018987578912012932921298541
892349803498145031034563210327898101879647810123871092567432
785056712387236567687654389410787632768756303294562783458943
176120987656547858998545076585894583459843214785103698327874
015431234543218947657898145894983298708941025672234567016761
329122345692105438941763236783470165617652912341013053205430
478031001785676323430154100102565674320543805432332122124321
567649872434985610121894321211056589211230796901440345034234
456659763323810765456765894323987401108921687878981236565105
306778654310329876365498765012342322317834510967892387156076
219865011078478901278321001231451015436123423456785493087189
652104102569560110669125198340760896895034587655476334196892
765233243458721321701034567654878987764105694344301243234561
894310321029832459852567878723965430653298743213210358765410
132123478010741069743478989014436321541056543401821569898324
098034569123658978654321876101521087632347812114981678876543
107765678034567867569270965437698794545938903003470549987432
256872345621098654378187602348967003897821094012561232789501
345901436438767789210094511059854112766123285723034341076521
217894387589656231234543223456743245675054176894125652112430
306105498678543140567672100145101230984169065765898763203431
495218321067012056478981041234230121243078434965235678976521
584349452652100987329891230765345698732154567874143454989210
673458763643211011010010049874556781235463456963056763474321
567647601781012567892102156743765470346322161012369812565232
498678432692123476543103095652834387457210052623871001450143
304509543543001989698234589501921098768921106780982341019898
213219601982132670787825676501432349810123235691987432870767
894348732676544561236910787432321056769894344302346549961251
765210145690125650345210097899867892110765654219854678450340
890100126780034743094303126934786543023234565678765012321231
765987034621129802185412235025696541032167876789874349876012
876856541234988012276543384110567832249054965694101256778123
965987650945876543543215493201378980158345434783450126789894
457871056876067875456906780110234589267210321692569034670765
320432347780128965307878767820199674307890160541078765521254
011876548991234534218349856936788765216543254332112340432345
432965432781049621029256743245215656325321067210003451201056
547876501632898756540178652101304567101452198760116764342767
656983432542765987438769789012453898212968765641985895433898
898792323101874104329054210589562456703879454332076016924567
125601017652963265012123323676571329894312303549165327810430
034340178943012378901012334568980016765601212678234456901321
73 changes: 41 additions & 32 deletions 2024/ts/day-11/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ const partOne = (input: number[], debug: boolean) => {
index += 1;
}
stones = nextStones;
dlog(`Loop ${loop} - ${stones}`);
dlog(`Loop ${loop} - ${stones.length}`);
dlog(` ${stones}`);
}
return stones.length;
};
Expand Down Expand Up @@ -99,38 +100,46 @@ const partOneLinkedList = (input: number[], debug: boolean) => {
};

const partTwo = (input: number[], debug: boolean) => {
let stones = input.slice();

const loopTarget = 10;

for (let loop = 1; loop <= loopTarget; loop++) {
const newStones = [];
let index = 0;

while (index < stones.length) {
const stone = stones[index];
if (stone === 0) {
newStones.push(1);
index += 1;
continue;
}
const stoneStr = stone.toString();
if (stoneStr.length % 2 === 0) {
const firstHalf = parseInt(stoneStr.slice(0, stoneStr.length / 2), 10);
const secondHalf = parseInt(stoneStr.slice(stoneStr.length / 2), 10);
newStones.push(firstHalf);
newStones.push(secondHalf);
index += 1;
continue;
}
const cache: Record<number, Record<number, number>> = {};

newStones.push(stones[index] * 2024);
index += 1;
const setCache = (value: number, blinks: number, count: number) => {
if (!cache[value]) {
cache[value] = {};
}
stones = newStones;
console.log(`Loop ${loop} - ${stones.length}`);
cache[value][blinks] = count;
}
return stones.length;

const getStoneCount = (value: number, blinks: number): number => {
if (cache[value] && cache[value][blinks]) {
return cache[value][blinks];
}
if (blinks === 0) {
setCache(value, blinks, 1);
return 1;
}
if (value === 0) {
const result = getStoneCount(1, blinks - 1);
setCache(value, blinks, result);
return result;
}
const valueStr = value.toString();
if (valueStr.length % 2 === 0) {
const firstHalf = parseInt(valueStr.slice(0, valueStr.length / 2), 10);
const secondHalf = parseInt(valueStr.slice(valueStr.length / 2), 10);
const firstCount = getStoneCount(firstHalf, blinks - 1);
const secondCount = getStoneCount(secondHalf, blinks - 1);
const result = firstCount + secondCount;
setCache(value, blinks, result);
return result;
}
const result = getStoneCount(value * 2024, blinks - 1);
setCache(value, blinks, result);
return result;
}

const result = input.map((item) => getStoneCount(item, 75)).sum();
return result;

};

const resultOne = (_: any, result: number) => {
Expand All @@ -153,9 +162,9 @@ export const solution: Puzzle<number[], number> = {
day: 11,
input: () => processInput(11),
partOne,
//partTwo,
partTwo,
resultOne: resultOne,
//resultTwo: resultTwo,
resultTwo: resultTwo,
showInput,
test,
}
2 changes: 1 addition & 1 deletion 2024/ts/day-11/input.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
27 10647 103 9 0 5524 4594227 902936
773 79858 0 71 213357 2937 1 3998391
4 changes: 2 additions & 2 deletions 2024/ts/day-12/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const partOne = (input: string[][], debug: boolean) => {
for (let rindex = 0; rindex < height; rindex++) {
for (let cindex = 0; cindex < width; cindex++) {
const cell = input[rindex][cindex];

if (plots[cell] === undefined) {
plots[cell] = [];
}
Expand Down Expand Up @@ -130,7 +130,7 @@ export const solution: Puzzle<string[][], number> = {
partOne,
//partTwo,
resultOne: resultOne,
//resultTwo: resultTwo,
resultTwo: resultTwo,
showInput,
test,
}
Loading