mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 05:40:32 +01:00
Inline module
Because this is Terraform, and it's the ultimate optimisation technique
This commit is contained in:
@@ -2,17 +2,24 @@ variable "prev" {
|
||||
type = map(number)
|
||||
}
|
||||
|
||||
module "transform" {
|
||||
source = "../transform"
|
||||
for_each = var.prev
|
||||
|
||||
num = each.key
|
||||
}
|
||||
|
||||
locals {
|
||||
not_a_module = {
|
||||
for num, _ in var.prev : num => (
|
||||
tonumber(num) == 0
|
||||
? [1]
|
||||
: (
|
||||
length(tostring(num)) % 2 == 0
|
||||
? [
|
||||
tonumber(substr(tostring(num), 0, length(tostring(num)) / 2)),
|
||||
tonumber(substr(tostring(num), length(tostring(num)) / 2, length(tostring(num)) / 2)),
|
||||
]
|
||||
: [num * 2024]
|
||||
)
|
||||
)
|
||||
}
|
||||
by_value = flatten([
|
||||
for key, value in module.transform :
|
||||
[for result in value.result : { num = result, count = var.prev[key] }]
|
||||
for key, value in local.not_a_module :
|
||||
[for result in value : { num = result, count = var.prev[key] }]
|
||||
])
|
||||
|
||||
grouped = { for kv in local.by_value : kv.num => kv.count... }
|
||||
|
||||
Reference in New Issue
Block a user