mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement 2024 day 25 in Terraform
This commit is contained in:
23
2024/bonus/day25/main.tf
Normal file
23
2024/bonus/day25/main.tf
Normal 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)])
|
||||
}
|
||||
@@ -87,3 +87,12 @@ module "day19" {
|
||||
output "day19_1" {
|
||||
value = module.day19.part1
|
||||
}
|
||||
|
||||
module "day25" {
|
||||
source = "./day25"
|
||||
input = file("../inputs/25.txt")
|
||||
}
|
||||
|
||||
output "day25_1" {
|
||||
value = module.day25.part1
|
||||
}
|
||||
|
||||
@@ -164,3 +164,20 @@ run "day19" {
|
||||
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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user