From 41abdea33b1f5503239c62f419841f08b9d22e87 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Mon, 5 Dec 2022 21:32:22 +0100 Subject: [PATCH] 05_2 --- day05/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/day05/index.js b/day05/index.js index 692c2c2..869cf9e 100644 --- a/day05/index.js +++ b/day05/index.js @@ -29,8 +29,14 @@ input.split('\n').forEach(line => { const howMany = parseInt(splitLine[1]), from = parseInt(splitLine[3]) - 1, to = parseInt(splitLine[5]) - 1; + const tempStack = []; + for(let i = 0; i < howMany; i++) { - stacks[to].push(stacks[from].pop()); + tempStack.push(stacks[from].pop()); + } + + for(let i = 0; i < howMany; i++) { + stacks[to].push(tempStack.pop()) } } });