From fdaadfe184d6a6d30da9ec0f4e8b53e41d455332 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Thu, 19 Dec 2024 23:24:11 +0100 Subject: [PATCH] Implement day 19 part 1 in Terraform --- 2024/bonus/day19/main.tf | 13 +++++++++++++ 2024/bonus/main.tf | 9 +++++++++ 2024/bonus/tests.tftest.hcl | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 2024/bonus/day19/main.tf diff --git a/2024/bonus/day19/main.tf b/2024/bonus/day19/main.tf new file mode 100644 index 0000000..21e7904 --- /dev/null +++ b/2024/bonus/day19/main.tf @@ -0,0 +1,13 @@ +variable "input" { + type = string +} + +locals { + parts = split("\n\n", chomp((var.input))) + patterns = replace(local.parts[0], ", ", "|") + valid = [for line in split("\n", local.parts[1]) : line if length(regexall("^(${local.patterns})+$", line)) > 0] +} + +output "part1" { + value = length(local.valid) +} diff --git a/2024/bonus/main.tf b/2024/bonus/main.tf index c45370e..8149729 100644 --- a/2024/bonus/main.tf +++ b/2024/bonus/main.tf @@ -78,3 +78,12 @@ output "day11_1" { output "day11_2" { value = module.day11.part2 } + +module "day19" { + source = "./day19" + input = file("../inputs/19.txt") +} + +output "day19_1" { + value = module.day19.part1 +} diff --git a/2024/bonus/tests.tftest.hcl b/2024/bonus/tests.tftest.hcl index a6127ff..1fc06f1 100644 --- a/2024/bonus/tests.tftest.hcl +++ b/2024/bonus/tests.tftest.hcl @@ -147,3 +147,20 @@ run "day11" { error_message = "Part1 output is wrong" } } + +run "day19" { + command = plan + + module { + source = "./day19" + } + + variables { + input = file("../tests/samples/19.txt") + } + + assert { + condition = output.part1 == 6 + error_message = "Part1 output is wrong" + } +}