2024 day 19 part 1 with my dumbest solution yet
This commit is contained in:
parent
eefce852c2
commit
136d031345
10
2024/19/example.txt
Normal file
10
2024/19/example.txt
Normal 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
26
2024/19/solution.nix
Normal 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;
|
||||
};
|
||||
}
|
|
@ -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"
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue