Implement 2024 day 25 in Terraform

This commit is contained in:
2024-12-26 15:13:46 +01:00
parent f3a3e1fca3
commit 073b576fd8
3 changed files with 49 additions and 0 deletions

23
2024/bonus/day25/main.tf Normal file
View File

@@ -0,0 +1,23 @@
variable "input" {
type = string
}
locals {
blocks = split("\n\n", chomp(var.input))
heights = [
for block in local.blocks : [
for i in range(5) : length([
for line in split("\n", block) : line if substr(line, i, 1) == "#"
])
]
]
locks = [for i in range(length(local.blocks)) : local.heights[i] if startswith(local.blocks[i], "#####")]
keys = [for i in range(length(local.blocks)) : local.heights[i] if !startswith(local.blocks[i], "#####")]
combined = concat([for lock in local.locks : [for key in local.keys : [for i in range(5) : lock[i] + key[i] <= 7]]]...)
}
output "part1" {
value = length([for combination in local.combined : combination if alltrue(combination)])
}

View File

@@ -87,3 +87,12 @@ module "day19" {
output "day19_1" { output "day19_1" {
value = module.day19.part1 value = module.day19.part1
} }
module "day25" {
source = "./day25"
input = file("../inputs/25.txt")
}
output "day25_1" {
value = module.day25.part1
}

View File

@@ -164,3 +164,20 @@ run "day19" {
error_message = "Part1 output is wrong" error_message = "Part1 output is wrong"
} }
} }
run "day25" {
command = plan
module {
source = "./day25"
}
variables {
input = file("../tests/samples/25.txt")
}
assert {
condition = output.part1 == 3
error_message = "Part1 output is wrong"
}
}