From 51af648715a8ae1231626691bdb90cf75d3531c3 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Tue, 19 Dec 2023 20:55:33 +0200 Subject: [PATCH] refactor --- src/2023/day19.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/2023/day19.js b/src/2023/day19.js index 65360624..25dcfdf9 100644 --- a/src/2023/day19.js +++ b/src/2023/day19.js @@ -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; }