-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.mjs
37 lines (33 loc) · 809 Bytes
/
utils.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import path from "node:path";
import fs from "node:fs";
export const readInput = (importMeta) => {
return fs.readFileSync(
`${path.basename(importMeta.url, path.extname(importMeta.url))}.in`,
"utf8",
);
};
export const getAdjacentPositions = (i, j) => [
...getStraightAdjacentPositions(i, j),
[i + 1, j + 1],
[i + 1, j - 1],
[i - 1, j - 1],
[i - 1, j + 1],
];
export const getStraightAdjacentPositions = (i, j) => [
[i, j + 1],
[i, j - 1],
[i + 1, j],
[i - 1, j],
];
export const timeIt = (fn, name) => {
let totalTime = 0;
process.on("exit", () => {
console.log(`Time taken by ${name}: ${totalTime}`);
});
return (...args) => {
const start = performance.now();
const res = fn(...args);
totalTime += performance.now() - start;
return res;
};
};