Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
NullDev committed Dec 7, 2024
1 parent d9ff75d commit 5a18f37
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions 2024/Day_07/part_1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
// = Copyright (c) NullDev = //
// ========================= //

/* eslint-disable no-sequences */

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

const pStart = performance.now();

const res = INPUT.reduce((
a, b, _, __, [tar, nStr] = b.split(": "), num = nStr.split(" ").map(Number),
gen = (
length, ops = ['+', '*'], res = [],
g = (combo) => combo.length === length ? res.push(combo) : ops.forEach(op => g(combo + op))
) => (g(''), res)
length, ops = ["+", "*"], r = [],
g = (combo) => combo.length === length ? r.push(combo) : ops.forEach(op => g(combo + op)),
) => (g(""), r),
) => gen(num.length - 1)
.some(ops => ops.split('').reduce((a, b, i) => b === '+' ? a + num[i + 1] : a * num[i + 1], num[0]) === Number(tar))
? a + Number(tar)
: a, 0);
.some(ops => ops.split("").reduce(
(a_, b_, i) => b_ === "+" ? a_ + num[i + 1] : a_ * num[i + 1], num[0],
) === Number(tar)) ? a + Number(tar) : a, 0);

const pEnd = performance.now();

Expand Down
6 changes: 4 additions & 2 deletions 2024/Day_07/part_2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
// = Copyright (c) NullDev = //
// ========================= //

/* eslint-disable no-sequences */

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

const pStart = performance.now();

const reach = (
tar, num, idx = 0, curr = num[0], memo = {}, key = `${idx}:${curr}`, nx = num[idx + 1]
tar, num, idx = 0, curr = num[0], memo = {}, key = `${idx}:${curr}`, nx = num[idx + 1],
) => {
if (key in memo) return memo[key];
if (idx === num.length - 1) return (memo[key] = curr === tar), memo[key];
Expand All @@ -24,7 +26,7 @@ const reach = (
};

const res = INPUT.reduce((
acc, line, _, __, [tar, nStr] = line.split(": "), num = nStr.split(" ").map(Number)
acc, line, _, __, [tar, nStr] = line.split(": "), num = nStr.split(" ").map(Number),
) => (acc + (reach(Number(tar), num) ? Number(tar) : 0)), 0);

const pEnd = performance.now();
Expand Down

0 comments on commit 5a18f37

Please sign in to comment.