Skip to content

Commit 073b576

Browse files
committed
Implement 2024 day 25 in Terraform
1 parent f3a3e1f commit 073b576

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

2024/bonus/day25/main.tf

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
variable "input" {
2+
type = string
3+
}
4+
5+
locals {
6+
blocks = split("\n\n", chomp(var.input))
7+
heights = [
8+
for block in local.blocks : [
9+
for i in range(5) : length([
10+
for line in split("\n", block) : line if substr(line, i, 1) == "#"
11+
])
12+
]
13+
]
14+
15+
locks = [for i in range(length(local.blocks)) : local.heights[i] if startswith(local.blocks[i], "#####")]
16+
keys = [for i in range(length(local.blocks)) : local.heights[i] if !startswith(local.blocks[i], "#####")]
17+
18+
combined = concat([for lock in local.locks : [for key in local.keys : [for i in range(5) : lock[i] + key[i] <= 7]]]...)
19+
}
20+
21+
output "part1" {
22+
value = length([for combination in local.combined : combination if alltrue(combination)])
23+
}

2024/bonus/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,12 @@ module "day19" {
8787
output "day19_1" {
8888
value = module.day19.part1
8989
}
90+
91+
module "day25" {
92+
source = "./day25"
93+
input = file("../inputs/25.txt")
94+
}
95+
96+
output "day25_1" {
97+
value = module.day25.part1
98+
}

2024/bonus/tests.tftest.hcl

+17
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,20 @@ run "day19" {
164164
error_message = "Part1 output is wrong"
165165
}
166166
}
167+
168+
run "day25" {
169+
command = plan
170+
171+
module {
172+
source = "./day25"
173+
}
174+
175+
variables {
176+
input = file("../tests/samples/25.txt")
177+
}
178+
179+
assert {
180+
condition = output.part1 == 3
181+
error_message = "Part1 output is wrong"
182+
}
183+
}

0 commit comments

Comments
 (0)