mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Implement 2024 day 14 part 1 in Terraform
This commit is contained in:
33
2024/bonus/day14/main.tf
Normal file
33
2024/bonus/day14/main.tf
Normal 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
|
||||||
|
}
|
||||||
@@ -92,6 +92,15 @@ output "day13_2" {
|
|||||||
value = module.day13.part2
|
value = module.day13.part2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module "day14" {
|
||||||
|
source = "./day14"
|
||||||
|
input = file("../inputs/14.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
output "day14_1" {
|
||||||
|
value = module.day14.part1
|
||||||
|
}
|
||||||
|
|
||||||
module "day19" {
|
module "day19" {
|
||||||
source = "./day19"
|
source = "./day19"
|
||||||
input = file("../inputs/19.txt")
|
input = file("../inputs/19.txt")
|
||||||
|
|||||||
@@ -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" {
|
run "day19" {
|
||||||
command = plan
|
command = plan
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user