Skip to content

Commit 9e552c9

Browse files
committed
More inlining
1 parent 329cd4e commit 9e552c9

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

2024/bonus/day11/step/main.tf

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,28 @@ variable "prev" {
33
}
44

55
locals {
6-
not_a_module = {
7-
for num, _ in var.prev : num => (
6+
by_value = flatten([
7+
for num, count in var.prev : (
88
tonumber(num) == 0
9-
? [1]
9+
? [{ number = 1, amount = count }]
1010
: (
1111
length(tostring(num)) % 2 == 0
1212
? [
13-
tonumber(substr(tostring(num), 0, length(tostring(num)) / 2)),
14-
tonumber(substr(tostring(num), length(tostring(num)) / 2, length(tostring(num)) / 2)),
13+
{
14+
number = tonumber(substr(tostring(num), 0, length(tostring(num)) / 2)),
15+
amount = count
16+
},
17+
{
18+
number = tonumber(substr(tostring(num), length(tostring(num)) / 2, length(tostring(num)) / 2)),
19+
amount = count,
20+
},
1521
]
16-
: [num * 2024]
22+
: [{ number = 2024 * num, amount = count }]
1723
)
1824
)
19-
}
20-
by_value = flatten([
21-
for key, value in local.not_a_module :
22-
[for result in value : { num = result, count = var.prev[key] }]
2325
])
2426

25-
grouped = { for kv in local.by_value : kv.num => kv.count... }
27+
grouped = { for kv in local.by_value : kv.number => kv.amount... }
2628
}
2729

2830
output "next" {

0 commit comments

Comments
 (0)