Advent of Code 2025 solutions
1export function randomRange(min: number, max: number) {
2 return Math.floor(Math.random() * (max - min + 1) + min);
3}
4
5export function digits(n: number) {
6 return Math.max(Math.floor(Math.log10(Math.abs(n))), 0) + 1;
7}
8
9export function isEven(n: number) {
10 return n % 2 === 0;
11}
12
13export function getDeterminant(matrix: number[][]) {
14 return matrix
15 .map((row) => row.reduce((acc, curr) => acc * curr, 1))
16 .reduce((acc, curr) => acc * curr, 1);
17}
18
19export function remainderMod(n: number, d: number) {
20 const q = parseInt((n / d) as any); // truncates to lower magnitude
21 return n - d * q;
22}
23
24export function remainderModBigInt(n: bigint, d: bigint) {
25 const q = BigInt((n / d) as any); // truncates to lower magnitude
26 return n - d * q;
27}