Skip to content

Commit fdaadfe

Browse files
committed
Implement day 19 part 1 in Terraform
1 parent dd07090 commit fdaadfe

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

2024/bonus/day19/main.tf

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
variable "input" {
2+
type = string
3+
}
4+
5+
locals {
6+
parts = split("\n\n", chomp((var.input)))
7+
patterns = replace(local.parts[0], ", ", "|")
8+
valid = [for line in split("\n", local.parts[1]) : line if length(regexall("^(${local.patterns})+$", line)) > 0]
9+
}
10+
11+
output "part1" {
12+
value = length(local.valid)
13+
}

2024/bonus/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,12 @@ output "day11_1" {
7878
output "day11_2" {
7979
value = module.day11.part2
8080
}
81+
82+
module "day19" {
83+
source = "./day19"
84+
input = file("../inputs/19.txt")
85+
}
86+
87+
output "day19_1" {
88+
value = module.day19.part1
89+
}

2024/bonus/tests.tftest.hcl

+17
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,20 @@ run "day11" {
147147
error_message = "Part1 output is wrong"
148148
}
149149
}
150+
151+
run "day19" {
152+
command = plan
153+
154+
module {
155+
source = "./day19"
156+
}
157+
158+
variables {
159+
input = file("../tests/samples/19.txt")
160+
}
161+
162+
assert {
163+
condition = output.part1 == 6
164+
error_message = "Part1 output is wrong"
165+
}
166+
}

0 commit comments

Comments
 (0)