Skip to content

Commit

Permalink
Implement day 19 part 1 in Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
bertptrs committed Dec 19, 2024
1 parent dd07090 commit fdaadfe
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 2024/bonus/day19/main.tf
Original file line number Diff line number Diff line change
@@ -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)
}
9 changes: 9 additions & 0 deletions 2024/bonus/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
17 changes: 17 additions & 0 deletions 2024/bonus/tests.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit fdaadfe

Please sign in to comment.