day 2 part 2 very late

This commit is contained in:
Sqaaakoi 2024-12-04 13:49:33 +11:00
parent 763be9b589
commit 7df462c08f
No known key found for this signature in database

16
day2.ts
View file

@ -20,3 +20,19 @@ function puzzle1() {
}
console.log("Puzzle 1", puzzle1());
function dampen_lists(row: number[]) {
const rows: number[][] = new Array(row.length).fill(row).map((_row, i) => {
const row = [..._row];
row.splice(i, 1);
return row;
});
return [row, ...rows].filter(safe_levels).length > 0;
}
function puzzle2() {
return rows.map((row) => row.split(/\s+/g).map(i => +i))
.filter(row => dampen_lists(row) || dampen_lists(row.toReversed())).length;
}
console.log("Puzzle 2", puzzle2());