Skip to content

Commit dc92b65

Browse files
committed
Inline loop
1 parent 5c030d5 commit dc92b65

File tree

2 files changed

+10
-29
lines changed

2 files changed

+10
-29
lines changed

2024/bonus/day05/is_correct/main.tf

Lines changed: 0 additions & 21 deletions
This file was deleted.

2024/bonus/day05/main.tf

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ locals {
88
disallow_rules = { for rule in local.rules : rule[1] => rule[0]... }
99

1010
updates = [for update_line in split("\n", local.parts[1]) : [for v in split(",", update_line) : tonumber(v)]]
11-
}
12-
13-
module "is_valid" {
14-
source = "./is_correct"
15-
count = length(local.updates)
1611

17-
update = local.updates[count.index]
18-
disallow_rules = local.disallow_rules
12+
scores = [
13+
for update in local.updates :
14+
alltrue([
15+
for i in range(1, length(update)) :
16+
!contains(
17+
flatten([for j in range(i) : lookup(local.disallow_rules, update[j], [])]),
18+
update[i]
19+
)
20+
]) ? update[floor(length(update) / 2)] : 0]
1921
}
2022

2123
output "part1" {
22-
value = sum(module.is_valid[*].valid)
24+
value = sum(local.scores[*])
2325
}

0 commit comments

Comments
 (0)