2024 day 19 part 1 with my dumbest solution yet

This commit is contained in:
Tristan 2024-12-19 15:26:40 +00:00
parent eefce852c2
commit 136d031345
3 changed files with 38 additions and 2 deletions

10
2024/19/example.txt Normal file
View file

@ -0,0 +1,10 @@
r, wr, b, g, bwu, rb, gb, br
brwrr
bggr
gbbr
rrbgbr
ubwu
bwurrg
brgr
bbrgwb

26
2024/19/solution.nix Normal file
View file

@ -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;
};
}

View file

@ -3,8 +3,8 @@
"aoc-inputs": { "aoc-inputs": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1734543082, "lastModified": 1734614378,
"narHash": "sha256-hU8vRkPOKfQqp34Ffx4INiz3l6HdwGcbfyHgqO4qheM=", "narHash": "sha256-vEsmquzc9r82OCVx2Q9WjdND7aOy39Oot3QDJcInhXk=",
"path": "/tmp/aoc-inputs", "path": "/tmp/aoc-inputs",
"type": "path" "type": "path"
}, },