Skip to content

Commit de68c87

Browse files
committed
day 22 part 1
1 parent e5a2f57 commit de68c87

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

2024/Day_22/part_1.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,21 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
88
// = Copyright (c) NullDev = //
99
// ========================= //
1010

11-
const INPUT = String(fs.readFileSync(path.join(__dirname, "input.txt"))).trim().split("\n");
11+
/* eslint-disable curly, no-param-reassign */
12+
13+
const INPUT = String(fs.readFileSync(path.join(__dirname, "input.txt"))).trim().split("\n").map(Number);
1214

1315
const pStart = performance.now();
1416

15-
//
16-
// YOUR CODE HERE
17-
//
18-
const result = "...";
17+
const total = INPUT.reduce((acc, e) => acc + ((
18+
s, p = val => val >>> 0 & 0xFFFFFF, // OR val 2^24 = 16777216 (secret mod 2^24)
19+
) => {
20+
for (let i = 0; i < 2000; i++) (s = p(s ^ p(s * 64))) // mul / div by n (64, 32, 2048), XOR, prune
21+
&& (s = p(s ^ p(Math.floor(s / 32)))) && (s = p(s ^ p(s * 2048)));
22+
return s;
23+
})(e), 0);
1924

2025
const pEnd = performance.now();
2126

22-
console.log("<DESCRIPTION>: " + result);
27+
console.log("SUM OF 2000TH SECRET NUMBER: " + total);
2328
console.log(pEnd - pStart);

0 commit comments

Comments
 (0)