Skip to content

Commit

Permalink
Day 11 [Part 1]
Browse files Browse the repository at this point in the history
  • Loading branch information
Av32000 committed Dec 11, 2024
1 parent 75cd20e commit 518c9fd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions 11/part1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const { readFileSync } = require("fs");
// Parse Input
const inputFile = "input.txt";
const input = readFileSync(inputFile)
.toString()
.trim()
.split(" ")
.map((x) => parseInt(x));

function splitNumber(num) {
const str = num.toString();
const half = str.length / 2;
const firstPart = str.slice(0, half);
const secondPart = str.slice(half);
return [parseInt(firstPart), parseInt(secondPart)];
}

function tick() {
let toApply = [];
input.forEach((e, i) => {
if (e == 0) input[i] = 1;
else if (e.toString().split("").length % 2 == 0) {
let parts = splitNumber(e);
input[i] = parts[0];
toApply.push([i + 1, parts[1]]);
} else {
input[i] = e * 2024;
}
});

toApply.forEach((e) => {
input.splice(e[0], 0, e[1]);
});
}

for (let i = 0; i < 25; i++) {
process.stdout.write(
`Tick : ${i + 1}/${25}. Current Result : ${input.length}\r`
);
tick();
}

console.log("\n", input.length);

0 comments on commit 518c9fd

Please sign in to comment.