mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 13:50:32 +01:00
Implement day 8 2024 in Terraform
This commit is contained in:
54
2024/bonus/day08/main.tf
Normal file
54
2024/bonus/day08/main.tf
Normal file
@@ -0,0 +1,54 @@
|
||||
variable "input" {
|
||||
type = string
|
||||
default = <<-EOT
|
||||
............
|
||||
........0...
|
||||
.....0......
|
||||
.......0....
|
||||
....0.......
|
||||
......A.....
|
||||
............
|
||||
............
|
||||
........A...
|
||||
.........A..
|
||||
............
|
||||
............
|
||||
EOT
|
||||
|
||||
}
|
||||
|
||||
locals {
|
||||
lines = split("\n", chomp(var.input))
|
||||
height = length(local.lines)
|
||||
width = length(local.lines[0])
|
||||
|
||||
antennae = concat([
|
||||
for y in range(local.height) :
|
||||
[
|
||||
for x in range(local.width) :
|
||||
[substr(local.lines[y], x, 1), x, y]
|
||||
if substr(local.lines[y], x, 1) != "."
|
||||
]
|
||||
]...)
|
||||
|
||||
by_freq = {
|
||||
for antenna in local.antennae :
|
||||
antenna[0] => [antenna[1], antenna[2]]...
|
||||
}
|
||||
}
|
||||
|
||||
module "freq" {
|
||||
source = "./freq"
|
||||
for_each = local.by_freq
|
||||
width = local.width
|
||||
height = local.height
|
||||
antennae = each.value
|
||||
}
|
||||
|
||||
output "part1" {
|
||||
value = length(setunion([for _, v in module.freq : v.nodes1]...))
|
||||
}
|
||||
|
||||
output "part2" {
|
||||
value = length(setunion([for _, v in module.freq : v.nodes2]...))
|
||||
}
|
||||
Reference in New Issue
Block a user