From bc9d1b45f4a76d05ea7df41d9b1343c75e98dba4 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Sat, 9 Dec 2023 22:43:48 +0100 Subject: [PATCH] reverse direction compared to part1 --- Day9/Part2.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Day9/Part2.js b/Day9/Part2.js index 6782614..91ad674 100644 --- a/Day9/Part2.js +++ b/Day9/Part2.js @@ -20,13 +20,13 @@ const predictions = histories.map((e) => { }, []); } const last = sequences.pop(); - const extrapolated = [[...last, last[0]]]; + let extrapolated = [last[0], ...last]; for (const s of sequences.reverse()) { - const current = s.pop(); - const last = extrapolated.pop().pop(); - extrapolated.push([...s, current + last]); + const current = s.shift(); + const last = extrapolated.shift(); + extrapolated = [current - last, ...s]; } - return extrapolated.pop().pop(); + return extrapolated.shift(); }); const sum = predictions.reduce((a, i) => a + i); console.log(sum);