Skip to content

Commit

Permalink
Day 2 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
NullDev committed Dec 2, 2024
1 parent 636c6a3 commit fea084b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions 2024/Day_02/part_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,27 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
// = Copyright (c) NullDev = //
// ========================= //

const INPUT = String(fs.readFileSync(path.join(__dirname, "input.txt"))).trim().split("\n");
const INPUT = String(fs.readFileSync(path.join(__dirname, "input.txt"))).trim().split("\n").filter(Boolean);

const pStart = performance.now();

//
// YOUR CODE HERE
//
const result = "...";
const res = INPUT.filter(
(line, _, __, levels = line.split(" ").map(str => Number(str)),
) => levels.every((level, i, arr) =>
i === 0 ||
(Math.abs(level - arr[i - 1]) >= 1 &&
Math.abs(level - arr[i - 1]) <= 3 &&
((arr[1] - arr[0]) < 0 ? level <= arr[i - 1] : level >= arr[i - 1])),
) || levels.some((___, i, arr) =>
arr.filter((____, j) => i !== j).every((level, k, newArr) =>
k === 0 ||
(Math.abs(level - newArr[k - 1]) >= 1 &&
Math.abs(level - newArr[k - 1]) <= 3 &&
((newArr[1] - newArr[0]) < 0 ? level <= newArr[k - 1] : level >= newArr[k - 1])),
),
)).length;

const pEnd = performance.now();

console.log("<DESCRIPTION>: " + result);
console.log("NEW SAFE REPORTS: " + res);
console.log(pEnd - pStart);
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ I also tried to experiment with a couple of different things:

**2024** <a name="best-2024"></a>

- One-Liner in [Day_02/part_1.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_04/part_1.js)
- One-Liner in [Day_02/part_1.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_02/part_1.js) and [Day_02/part_2.js](https://github.com/NullDev/Advent-of-Code/blob/master/2024/Day_02/part_2.js)

<hr>

Expand Down

0 comments on commit fea084b

Please sign in to comment.