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 ];