Implement 2024 day 3 part 2 in Terraform

No one's going to stop me, not even common sense
This commit is contained in:
2024-12-03 19:33:47 +01:00
parent ff2e421437
commit 608f3dc621
4 changed files with 53 additions and 0 deletions

View File

@@ -4,8 +4,21 @@ variable "input" {
locals {
muls = regexall("mul\\((\\d+),(\\d+)\\)", var.input)
ops = regexall("(don't\\(\\)|do\\(\\)|mul\\((\\d+),(\\d+)\\))", var.input)
}
module "should_execute" {
count = length(local.ops)
source = "./should_execute"
index = count.index
ops = local.ops
}
output "part1" {
value = sum([for mul in local.muls : parseint(mul[1], 10) * parseint(mul[0], 10)])
}
output "part2" {
value = sum(module.should_execute[*].value)
}