diff --git a/2024/09/bad.solution.nix b/2024/09/bad.solution.nix index 05c6b61..e00bd0a 100644 --- a/2024/09/bad.solution.nix +++ b/2024/09/bad.solution.nix @@ -114,9 +114,6 @@ in { inherit data disk defrag defragged checksum fullDisk; part1result = defragged |> checksum; - - # defraggedFullDisk = defragFullDisk fullDisk; - - # part1result = (defragFullDisk fullDisk).acc |> checksumFullDisk; + part2result = "My solution is too slow for part 2"; } diff --git a/2024/09/solution.nix b/2024/09/solution.nix new file mode 100644 index 0000000..5e6a61a --- /dev/null +++ b/2024/09/solution.nix @@ -0,0 +1,13 @@ +pkgs: input: let + inherit (pkgs) lib; + nix-solution = import ./bad.solution.nix pkgs input; + 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 nix-solution // { + javascript = { + part1result = bun-run ./solution.js; + part2result = bun-run ./solution2.js; + }; +} diff --git a/2024/09/bad.solution.test.nix b/2024/09/solution.test.nix similarity index 100% rename from 2024/09/bad.solution.test.nix rename to 2024/09/solution.test.nix diff --git a/2024/default.nix b/2024/default.nix new file mode 100644 index 0000000..b9a6f21 --- /dev/null +++ b/2024/default.nix @@ -0,0 +1,18 @@ +{pkgs ? import {}, aoc-inputs ? "/tmp/aoc-inputs"}: +let + inherit (pkgs) lib; +in +(lib.range 1 11 + |> map (i: let id = lib.fixedWidthNumber 2 i; in { + name = "day-${id}"; + value = let + solution = import ./${id}/solution.nix pkgs; + example = (pkgs.lib.readFile ./${id}/example.txt); + input = (pkgs.lib.readFile "${aoc-inputs}/${id}"); + in { + example = solution example; + real = solution input; + }; + }) + |> builtins.listToAttrs + ) diff --git a/2024/flake.nix b/2024/flake.nix index 815c2cb..e1b9153 100644 --- a/2024/flake.nix +++ b/2024/flake.nix @@ -41,27 +41,5 @@ }; }) |> builtins.listToAttrs - ) // { - - day-09 = let - solution = import ./09/bad.solution.nix pkgs; - example = (pkgs.lib.readFile ./09/example.txt); - input = "${aoc-inputs}/09"; - in { - example = solution example; - real.part1result = "My solution doesn't work on the real input :("; - javascript = { - part1result = pkgs.runCommand "2024day9part1" {} '' - ${lib.getExe pkgs.bun} ${./09/solution.js} ${input} > $out - '' |> builtins.readFile; - part2result = pkgs.runCommand "2024day9part1" {} '' - ${lib.getExe pkgs.bun} ${./09/solution2.js} ${input} > $out - '' |> builtins.readFile; - }; - test = tix.run [ - ./09/solution.test.nix - ]; - }; - - }; + ); }