From 5fb5222b15e6e3cd4762865eb1570f83a213d5a7 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Tue, 12 Dec 2023 13:50:27 +0200 Subject: [PATCH] optimization --- src/2023/day12.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/2023/day12.js b/src/2023/day12.js index 7f3ade39..7a134383 100644 --- a/src/2023/day12.js +++ b/src/2023/day12.js @@ -2,13 +2,12 @@ function add(queue, next) { const remain = (next.pattern.match(/[^.]/g) || []).length; if (remain + next.buffer < next.counts.reduce((a, b) => a + b, 0)) return; - const queued = queue.map.get(JSON.stringify(next)); - if (queued) { - queued.x += next.x; - return; - } else { + const { pattern, counts, buffer } = next; + const queued = queue.map.get(JSON.stringify({ pattern, counts, buffer })); + if (queued) queued.x += next.x; + else { queue.arr.push(next); - queue.map.set(JSON.stringify(next), next); + queue.map.set(JSON.stringify({ pattern, counts, buffer }), next); } }