mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-27 13:50:32 +01:00
Implement efficient algorithm in TF
This commit is contained in:
@@ -4,12 +4,15 @@ variable "input" {
|
||||
|
||||
locals {
|
||||
nums = [for s in split(" ", chomp(var.input)) : tonumber(s)]
|
||||
|
||||
grouped = { for num in local.nums : num => 1... }
|
||||
total = { for k, v in local.grouped : k => sum(v) }
|
||||
}
|
||||
|
||||
module "step1" {
|
||||
source = "./step"
|
||||
|
||||
prev = local.nums
|
||||
prev = local.total
|
||||
}
|
||||
|
||||
module "step2" {
|
||||
@@ -157,5 +160,5 @@ module "step25" {
|
||||
}
|
||||
|
||||
output "part1" {
|
||||
value = length(flatten(module.step25.next))
|
||||
value = sum(values(module.step25.next))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user