Skip to content

Commit

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

0 comments on commit 073b576

Please sign in to comment.