Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
shahata committed Dec 12, 2023
1 parent d007874 commit 5fb5222
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/2023/day12.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 5fb5222

Please sign in to comment.