From 196cde6dcb9f2e53162684c3b6bedbcf2a5cbf48 Mon Sep 17 00:00:00 2001 From: tristan Date: Thu, 19 Dec 2024 15:53:13 +0000 Subject: [PATCH] 2024 day 19 part 1 but it actually finishes executing in javascript --- 2024/09/solution.js | 2 -- 2024/19/solution.js | 15 +++++++++++++++ 2024/19/solution.nix | 14 ++++++++++---- 2024/flake.lock | 4 ++-- 2024/flake.nix | 4 ---- 5 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 2024/19/solution.js diff --git a/2024/09/solution.js b/2024/09/solution.js index d6de988..7cda01c 100644 --- a/2024/09/solution.js +++ b/2024/09/solution.js @@ -1,8 +1,6 @@ const input = (await Bun.file(Bun.argv[2]).text()).trim() -// const input = "12345"; - const files = []; const spaces = []; diff --git a/2024/19/solution.js b/2024/19/solution.js new file mode 100644 index 0000000..22c22d3 --- /dev/null +++ b/2024/19/solution.js @@ -0,0 +1,15 @@ + +const input = (await Bun.file(Bun.argv[2]).text()).trim() + +const [towels, desired] = input.split("\n\n") + +const regex = new RegExp(`^(${towels.split(", ").join("|")})+$`) + +const lines = desired.split("\n") + +let count = 0; +for (const line of lines) { + if (regex.test(line)) {count ++} +} +console.log(count) + diff --git a/2024/19/solution.nix b/2024/19/solution.nix index 8712e12..35c8f85 100644 --- a/2024/19/solution.nix +++ b/2024/19/solution.nix @@ -1,4 +1,4 @@ -{input ? "", lib, ...}: let +{input ? "", lib, pkgs, ...}: let inherit (builtins) elemAt filter length; exampleIn = lib.readFile ./example.txt; @@ -8,7 +8,7 @@ towels = elemAt parts 0 |> lib.splitString ", "; regex = ''(${builtins.concatStringsSep "|" towels})+''; desired = elemAt parts 1 |> lib.splitString "\n"; - matches = desired |> map (lib.match regex); + matches = desired |> map (e: lib.traceSeq e (lib.match regex e)); in { inherit towels regex desired matches; count = matches @@ -16,11 +16,17 @@ |> length; }; + input-file = pkgs.writeText "input.txt" input; + bun-run = js-file: pkgs.runCommand "2024day9" {} '' + ${lib.getExe pkgs.bun} ${js-file} ${input-file} > $out + '' |> builtins.readFile |> lib.trim; + in { example = mkSolution { text = exampleIn; }; - real = mkSolution { - text = input; + real = throw "lol this solution is wayy too slow for the real input"; + javascript = { + part1result = lib.trace "this is a dumb and slow solution" (bun-run ./solution.js); }; } diff --git a/2024/flake.lock b/2024/flake.lock index b87dab2..05538a0 100644 --- a/2024/flake.lock +++ b/2024/flake.lock @@ -3,8 +3,8 @@ "aoc-inputs": { "flake": false, "locked": { - "lastModified": 1734614378, - "narHash": "sha256-vEsmquzc9r82OCVx2Q9WjdND7aOy39Oot3QDJcInhXk=", + "lastModified": 1734622191, + "narHash": "sha256-kWDExTEeBuscWOZNBCMXAqZtNQT0SiQCjp43yEPRQ3g=", "path": "/tmp/aoc-inputs", "type": "path" }, diff --git a/2024/flake.nix b/2024/flake.nix index 51a7592..8cec491 100644 --- a/2024/flake.nix +++ b/2024/flake.nix @@ -39,10 +39,6 @@ input = (pkgs.lib.readFile "${aoc-inputs}/${id}"); in { inherit solution; - example = solution example; - example2 = solution example2; - example3 = solution example3; - real = solution input; test = tix.run [ ./${id}/solution.test.nix ];