diff options
author | Marvin Borner | 2021-12-24 14:52:19 +0100 |
---|---|---|
committer | Marvin Borner | 2021-12-24 14:52:19 +0100 |
commit | de31e0d014d0f7d17eb736936ca1e7206ed690f9 (patch) | |
tree | b532e6bd86b486b1073687db72be8acdfdb882fe | |
parent | c373404f4229a0842f3e0fe8d0aff6efeb8f4e18 (diff) |
aah
-rw-r--r-- | 2021/24/solve.c | 43 | ||||
-rw-r--r-- | 2021/24/solve.js | 56 |
2 files changed, 99 insertions, 0 deletions
diff --git a/2021/24/solve.c b/2021/24/solve.c new file mode 100644 index 0000000..8ab524d --- /dev/null +++ b/2021/24/solve.c @@ -0,0 +1,43 @@ +#include <math.h> +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + +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 }; + +int main(int argc, char *argv[]) +{ + srand(time(0)); + long w = 19599999999999; + + char ws[15]; + while (1) { + sprintf(ws, "%lu", w); + + long x = 0, y = 0, z = 0; + for (int i = 0; i < 14; i++) { + x = z; + x %= 26; + z /= zs[i]; + x += xs[i]; + x = (x == (ws[i] - '0')) ? 0 : 1; + y = 25; + y *= x; + y += 1; + z *= y; + y = (ws[i] - '0') + ys[i]; + y *= x; + z += y; + } + if (z == 0) { + printf("Found %ld %ld %ld -> %ld\n", w, x, y, z); + break; + } + if (w % 100000 == 0) + printf("%ld %ld\n", w, z); + w--; + } + return 0; +} diff --git a/2021/24/solve.js b/2021/24/solve.js new file mode 100644 index 0000000..55b4035 --- /dev/null +++ b/2021/24/solve.js @@ -0,0 +1,56 @@ +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; +} + +const tic = performance.now(); +console.log(part_one()); +console.log(part_two()); +const toc = performance.now(); +console.log("TIME: " + ((toc - tic) / 1000).toFixed(6) + " seconds"); |