Skip to content

Commit be2244e

Browse files
committed
Inline module
Because this is Terraform, and it's the ultimate optimisation technique
1 parent 395463d commit be2244e

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

2024/bonus/day11/step/main.tf

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@ variable "prev" {
22
type = map(number)
33
}
44

5-
module "transform" {
6-
source = "../transform"
7-
for_each = var.prev
8-
9-
num = each.key
10-
}
11-
125
locals {
6+
not_a_module = {
7+
for num, _ in var.prev : num => (
8+
tonumber(num) == 0
9+
? [1]
10+
: (
11+
length(tostring(num)) % 2 == 0
12+
? [
13+
tonumber(substr(tostring(num), 0, length(tostring(num)) / 2)),
14+
tonumber(substr(tostring(num), length(tostring(num)) / 2, length(tostring(num)) / 2)),
15+
]
16+
: [num * 2024]
17+
)
18+
)
19+
}
1320
by_value = flatten([
14-
for key, value in module.transform :
15-
[for result in value.result : { num = result, count = var.prev[key] }]
21+
for key, value in local.not_a_module :
22+
[for result in value : { num = result, count = var.prev[key] }]
1623
])
1724

1825
grouped = { for kv in local.by_value : kv.num => kv.count... }

2024/bonus/day11/transform/main.tf

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

0 commit comments

Comments
 (0)