From 136d0313456851c6ab8dc085389166d0f4fdd9d2 Mon Sep 17 00:00:00 2001 From: Tristan Date: Thu, 19 Dec 2024 15:26:40 +0000 Subject: [PATCH] 2024 day 19 part 1 with my dumbest solution yet --- 2024/19/example.txt | 10 ++++++++++ 2024/19/solution.nix | 26 ++++++++++++++++++++++++++ 2024/flake.lock | 4 ++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 2024/19/example.txt create mode 100644 2024/19/solution.nix 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" },