Skip to content

Commit

Permalink
Inline loop
Browse files Browse the repository at this point in the history
  • Loading branch information
bertptrs committed Dec 27, 2024
1 parent 5c030d5 commit dc92b65
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 29 deletions.
21 changes: 0 additions & 21 deletions 2024/bonus/day05/is_correct/main.tf

This file was deleted.

18 changes: 10 additions & 8 deletions 2024/bonus/day05/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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[*])
}

0 comments on commit dc92b65

Please sign in to comment.