Implement 2024 day 14 part 1 in Terraform

This commit is contained in:
2024-12-27 21:14:28 +01:00
parent d07bb9235b
commit 5c030d5272
3 changed files with 61 additions and 0 deletions

33
2024/bonus/day14/main.tf Normal file
View File

@@ -0,0 +1,33 @@
variable "input" {
type = string
}
variable "width" {
type = number
default = 101
}
variable "height" {
type = number
default = 103
}
locals {
lines = regexall("p=(-?\\d+),(-?\\d+) v=(-?\\d+),(-?\\d+)", var.input)
positions = [
for line in local.lines :
[
((line[0] + 100 * line[2]) % var.width + var.width) % var.width,
((line[1] + 100 * line[3]) % var.height + var.height) % var.height,
]
]
q1 = length([for pos in local.positions : pos if pos[0] < floor(var.width / 2) && pos[1] < floor(var.height / 2)])
q2 = length([for pos in local.positions : pos if pos[0] > floor(var.width / 2) && pos[1] < floor(var.height / 2)])
q3 = length([for pos in local.positions : pos if pos[0] < floor(var.width / 2) && pos[1] > floor(var.height / 2)])
q4 = length([for pos in local.positions : pos if pos[0] > floor(var.width / 2) && pos[1] > floor(var.height / 2)])
}
output "part1" {
value = local.q1 * local.q2 * local.q3 * local.q4
}

View File

@@ -92,6 +92,15 @@ output "day13_2" {
value = module.day13.part2
}
module "day14" {
source = "./day14"
input = file("../inputs/14.txt")
}
output "day14_1" {
value = module.day14.part1
}
module "day19" {
source = "./day19"
input = file("../inputs/19.txt")

View File

@@ -165,6 +165,25 @@ run "day13" {
}
}
run "day14" {
command = plan
module {
source = "./day14"
}
variables {
input = file("../tests/samples/14.txt")
height = 7
width = 11
}
assert {
condition = output.part1 == 12
error_message = "Part1 output is wrong"
}
}
run "day19" {
command = plan