123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import fs from "node:fs";
- export function loadInput(dayNumber, parsingFunction, literalPath = false) {
- let filePath = literalPath ? dayNumber : `./inputs/day_${dayNumber}.input`;
- const data = fs.readFileSync(filePath, "utf8");
- return typeof parsingFunction == "function" ? parsingFunction(data) : data;
- }
- export function numericAscSort(a, b) {
- return clamp(a - b);
- }
- export function strToInt(string) {
- return parseInt(string, 10);
- }
- export function clamp(value, min = -1, max = 1) {
- return Math.max(min, Math.min(max, value));
- }
- export function deepClone(value) {
- return JSON.parse(JSON.stringify(value));
- }
|