2024-12-02 03:22:49 -07:00
|
|
|
export async function solve() {
|
2024-12-03 21:42:57 -07:00
|
|
|
return await Deno.readTextFile(import.meta.dirname + "/input.txt").then((f) =>
|
2024-12-02 03:22:49 -07:00
|
|
|
f.split("\n").filter((l) => {
|
|
|
|
const report = l.split(" ").map((s) => +s);
|
|
|
|
const increasing = report[0] < report[1];
|
|
|
|
let last = report[0];
|
|
|
|
for (const number of report.slice(1)) {
|
|
|
|
if (number > last && !increasing) return false;
|
|
|
|
if (number < last && increasing) return false;
|
|
|
|
if (Math.abs(number - last) < 1 || Math.abs(number - last) > 3) return false;
|
|
|
|
|
|
|
|
last = number;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}).reduce(acc => acc + 1, 0)
|
|
|
|
);
|
|
|
|
}
|