diff --git a/2024/bonus/day05/is_correct/main.tf b/2024/bonus/day05/is_correct/main.tf deleted file mode 100644 index cde3103..0000000 --- a/2024/bonus/day05/is_correct/main.tf +++ /dev/null @@ -1,21 +0,0 @@ -variable "update" { - type = list(number) -} - -variable "disallow_rules" { - type = map(list(number)) -} - -locals { - not_disallowed = alltrue([ - for i in range(1, length(var.update)) : - !contains( - flatten([for j in range(i) : lookup(var.disallow_rules, var.update[j], [])]), - var.update[i] - ) - ]) -} - -output "valid" { - value = local.not_disallowed ? var.update[floor(length(var.update) / 2)] : 0 -} diff --git a/2024/bonus/day05/main.tf b/2024/bonus/day05/main.tf index f553da5..a774a11 100644 --- a/2024/bonus/day05/main.tf +++ b/2024/bonus/day05/main.tf @@ -8,16 +8,18 @@ locals { disallow_rules = { for rule in local.rules : rule[1] => rule[0]... } updates = [for update_line in split("\n", local.parts[1]) : [for v in split(",", update_line) : tonumber(v)]] -} - -module "is_valid" { - source = "./is_correct" - count = length(local.updates) - update = local.updates[count.index] - disallow_rules = local.disallow_rules + scores = [ + for update in local.updates : + alltrue([ + for i in range(1, length(update)) : + !contains( + flatten([for j in range(i) : lookup(local.disallow_rules, update[j], [])]), + update[i] + ) + ]) ? update[floor(length(update) / 2)] : 0] } output "part1" { - value = sum(module.is_valid[*].valid) + value = sum(local.scores[*]) }