mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 13:50:32 +01:00
Implement 2024 day 3 part 2 in Terraform
No one's going to stop me, not even common sense
This commit is contained in:
19
2024/bonus/day03/should_execute/main.tf
Normal file
19
2024/bonus/day03/should_execute/main.tf
Normal file
@@ -0,0 +1,19 @@
|
||||
variable "ops" {
|
||||
type = list(list(string))
|
||||
}
|
||||
|
||||
variable "index" {
|
||||
type = number
|
||||
}
|
||||
|
||||
locals {
|
||||
is_mul = startswith(var.ops[var.index][0], "mul")
|
||||
subslice = reverse(slice(var.ops[*][0], 0, var.index))
|
||||
|
||||
do_pos = contains(local.subslice, "do()") ? index(local.subslice, "do()") : var.index
|
||||
dont_pos = contains(local.subslice, "don't()") ? index(local.subslice, "don't()") : var.index + 1
|
||||
}
|
||||
|
||||
output "value" {
|
||||
value = (local.is_mul && local.do_pos < local.dont_pos) ? (parseint(var.ops[var.index][1], 10) * parseint(var.ops[var.index][2], 10)) : 0
|
||||
}
|
||||
Reference in New Issue
Block a user