mirror of
https://github.com/Baipyrus/AoC-23.git
synced 2024-12-26 12:01:45 +00:00
calculate least common multiple of all cycle sizes
This commit is contained in:
parent
f7accd2a13
commit
633bfcdee5
@ -28,7 +28,11 @@ const cycles = maps
|
||||
}
|
||||
return { start: e, end: current, length: count };
|
||||
});
|
||||
console.log(cycles);
|
||||
const sizes = cycles.map((e) => e.length);
|
||||
const gcd = (a, b) => (b == 0 ? a : gcd(b, a % b));
|
||||
const lcm = (a, b) => (a / gcd(a, b)) * b;
|
||||
const total = sizes.reduce(lcm, 1);
|
||||
console.log(total);
|
||||
|
||||
const t1 = performance.now();
|
||||
console.log(`Runtime: ${t1 - t0}ms`);
|
||||
|
Loading…
Reference in New Issue
Block a user