aboutsummaryrefslogtreecommitdiff
path: root/2021/24
diff options
context:
space:
mode:
authorMarvin Borner2021-12-24 15:11:48 +0100
committerMarvin Borner2021-12-24 15:11:48 +0100
commit58f86002e905a8123bd94df8078e0ce697f4fe26 (patch)
treebde4e5c6c1fcc048c9112d1f35aea6e5dbdea41b /2021/24
parentde31e0d014d0f7d17eb736936ca1e7206ed690f9 (diff)
hehe
Diffstat (limited to '2021/24')
-rw-r--r--2021/24/Makefile4
-rw-r--r--2021/24/input252
-rw-r--r--2021/24/solve.c2
-rw-r--r--2021/24/solve.js53
4 files changed, 263 insertions, 48 deletions
diff --git a/2021/24/Makefile b/2021/24/Makefile
new file mode 100644
index 0000000..9295d89
--- /dev/null
+++ b/2021/24/Makefile
@@ -0,0 +1,4 @@
+run:
+ @node solve.js
+
+time: run
diff --git a/2021/24/input b/2021/24/input
new file mode 100644
index 0000000..549ccd6
--- /dev/null
+++ b/2021/24/input
@@ -0,0 +1,252 @@
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 14
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 14
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 14
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 2
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 14
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 1
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 13
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 15
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 5
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 5
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 5
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 12
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 9
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -7
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 3
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 1
+add x 13
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 13
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -8
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 2
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -5
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 1
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -10
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 11
+mul y x
+add z y
+inp w
+mul x 0
+add x z
+mod x 26
+div z 26
+add x -7
+eql x w
+eql x 0
+mul y 0
+add y 25
+mul y x
+add y 1
+mul z y
+mul y 0
+add y w
+add y 8
+mul y x
+add z y
diff --git a/2021/24/solve.c b/2021/24/solve.c
index 8ab524d..72bf9de 100644
--- a/2021/24/solve.c
+++ b/2021/24/solve.c
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <time.h>
+// Non-trial-and-error solution in solve.js
+
static const int xs[] = { 14, 14, 14, 12, 15, -12, -12, 12, -7, 13, -8, -5, -10, -7 };
static const int ys[] = { 14, 2, 1, 13, 5, 5, 5, 9, 3, 13, 2, 1, 11, 8 };
static const int zs[] = { 1, 1, 1, 1, 1, 26, 26, 1, 26, 1, 26, 26, 26, 26 };
diff --git a/2021/24/solve.js b/2021/24/solve.js
index 55b4035..1a63e72 100644
--- a/2021/24/solve.js
+++ b/2021/24/solve.js
@@ -1,56 +1,13 @@
const { _, performance } = require("perf_hooks");
const fs = require("fs");
-const data = fs.readFileSync("input", "utf8").split("inp").map(block => block.split("\n")).slice(1);
-function part_one() {
- let res = 0;
-
- // console.log(data);
- const xs = data.map(block => +block[5].split(" ").slice(-1)[0]);
- const ys = data.map(block => +block[15].split(" ").slice(-1)[0]);
- const zs = data.map(block => +block[4].split(" ").slice(-1)[0]);
- console.log(xs,ys,zs);
-
- let w = 89999999999999;
- while (1) {
- const ws = Array.from(String(w), Number);
-
- let z = 0;
- for (let i = 0; i < 14; i++) {
- let x = 0, y = 0;
- x = z;
- x %= 26;
- z = Math.floor(z / zs[i]);
- x += xs[i];
- x = (x == ws[i]) ? 0 : 1;
- y = 25;
- y *= x;
- y += 1;
- z *= y;
- y = ws[i] + ys[i];
- y *= x;
- z += y;
- }
- if (z == 0) {
- console.log("Found", w, x, y, z);
- break;
- }
- if (w % 1000000 == 0)
- console.log(w, z);
- w--;
- }
-
- return w;
-}
-
-function part_two() {
- let res = 0;
-
- return res;
+function solve() {
+ n=[],m=[],t=[];
+ fs.readFileSync("input", "utf8").split("in").map(b=>b.split("\n")).slice(1).forEach((b,i)=>{if(b[4][6]=='1')t.push([i,+b[15].split(" ").slice(-1)[0]]);else{[j,x]=t.pop();d=x+ +b[5].split(" ").slice(-1)[0];if(d<0)[i,j,d]=[j,i,-d];m[i]=9;m[j]=9-d;n[i]=1+d;n[j]=1}})
+ console.log(m.join(""),n.join(""));
}
const tic = performance.now();
-console.log(part_one());
-console.log(part_two());
+solve();
const toc = performance.now();
console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds");