diff --git a/2024/19/example.txt b/2024/19/example.txt new file mode 100644 index 0000000..29648be --- /dev/null +++ b/2024/19/example.txt @@ -0,0 +1,10 @@ +r, wr, b, g, bwu, rb, gb, br + +brwrr +bggr +gbbr +rrbgbr +ubwu +bwurrg +brgr +bbrgwb diff --git a/2024/19/solution.nix b/2024/19/solution.nix new file mode 100644 index 0000000..8712e12 --- /dev/null +++ b/2024/19/solution.nix @@ -0,0 +1,26 @@ +{input ? "", lib, ...}: let + inherit (builtins) elemAt filter length; + + exampleIn = lib.readFile ./example.txt; + + mkSolution = {text}: let + parts = text |> lib.trim |> lib.splitString "\n\n"; + towels = elemAt parts 0 |> lib.splitString ", "; + regex = ''(${builtins.concatStringsSep "|" towels})+''; + desired = elemAt parts 1 |> lib.splitString "\n"; + matches = desired |> map (lib.match regex); + in { + inherit towels regex desired matches; + count = matches + |> filter (m: !isNull m) + |> length; + }; + +in { + example = mkSolution { + text = exampleIn; + }; + real = mkSolution { + text = input; + }; +} diff --git a/2024/flake.lock b/2024/flake.lock index 428cf6f..b87dab2 100644 --- a/2024/flake.lock +++ b/2024/flake.lock @@ -3,8 +3,8 @@ "aoc-inputs": { "flake": false, "locked": { - "lastModified": 1734543082, - "narHash": "sha256-hU8vRkPOKfQqp34Ffx4INiz3l6HdwGcbfyHgqO4qheM=", + "lastModified": 1734614378, + "narHash": "sha256-vEsmquzc9r82OCVx2Q9WjdND7aOy39Oot3QDJcInhXk=", "path": "/tmp/aoc-inputs", "type": "path" },