Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 19, 2023
1 parent 6c3059d commit 51af648
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/2023/day19.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ function run2(ranges, workflows, name = 'in') {
if (name === 'R') return 0;
for (const rule of workflows[name]) {
const { operator, key, value } = rule.condition;
const next = JSON.parse(JSON.stringify(ranges));
if (operator && ranges[key].min < value && ranges[key].max > value) {
if (!operator || (ranges[key].min < value && ranges[key].max > value)) {
const next = JSON.parse(JSON.stringify(ranges));
if (operator === '<') next[key].max = (ranges[key].min = value) - 1;
if (operator === '>') next[key].min = (ranges[key].max = value) + 1;
count += run2(next, workflows, rule.result);
}
count += run2(next, workflows, rule.result);
}
return count;
}
Expand Down

0 comments on commit 51af648

Please sign in to comment.