day 2 part 2 very late
This commit is contained in:
parent
763be9b589
commit
7df462c08f
1 changed files with 16 additions and 0 deletions
16
day2.ts
16
day2.ts
|
@ -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());
|
Loading…
Add table
Reference in a new issue