aboutsummaryrefslogtreecommitdiff
path: root/2022/05
diff options
context:
space:
mode:
authorMarvin Borner2022-12-05 09:04:45 +0100
committerMarvin Borner2022-12-05 09:04:45 +0100
commita36c6fe4b3fe93c936d40dcca41f5e8cbf4987d7 (patch)
tree915d2a1ec31b9ff01f61879bf93037ff3642a590 /2022/05
parentd5f822bcad063435ac1a48f0a0dae41a9b155d73 (diff)
golf? a bit
Diffstat (limited to '2022/05')
-rw-r--r--2022/05/solve.js15
-rw-r--r--2022/05/solve.py8
2 files changed, 19 insertions, 4 deletions
diff --git a/2022/05/solve.js b/2022/05/solve.js
new file mode 100644
index 0000000..9cdb3ec
--- /dev/null
+++ b/2022/05/solve.js
@@ -0,0 +1,15 @@
+function run(v)
+{
+ [s,p]=require("fs").readFileSync("input", "utf8").split("\n\n");
+ l=s.split("\n").slice(0,-1).map(a=>a.match(/.{1,4}/g))
+ s=l[0].map((c,i)=>l.map(r=>r[i])).map(a=>a.filter(b=>b[0]=='['))
+ p.split("\n").slice(0,-1).forEach(a=>{b=a.split(" ");w=+b[1];r=+b[3]-1;t=+b[5]-1;p=s[r].slice(0,w);if(!(v%2))p.reverse();s[t]=[...p,...s[t]];s[r].splice(0,w);});
+ return s.map(a=>a[0]).join("");
+}
+
+const tic = performance.now();
+console.log(run(9000));
+console.log(run(9001));
+const toc = performance.now();
+console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");
+
diff --git a/2022/05/solve.py b/2022/05/solve.py
index 8997d4e..fb996bc 100644
--- a/2022/05/solve.py
+++ b/2022/05/solve.py
@@ -18,10 +18,10 @@ def solve(mover_version):
stacks[i // 4].insert(0, cols[i])
i += 4
else:
- proc = line.replace("move ", "").replace("from ", "").replace("to ", "").replace("target ", "").split(" ")
- what = int(proc[0])
- source = int(proc[1]) - 1
- target = int(proc[2]) - 1
+ proc = line.split(" ")
+ what = int(proc[1])
+ source = int(proc[3]) - 1
+ target = int(proc[5]) - 1
crates = stacks[source][-what:]
if mover_version == 9000: