Skip to content

Commit 59b72df

Browse files
committed
2025: Optimize
1 parent d593e2e commit 59b72df

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

2025/src/day03_spec.lua

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ local util = require "util"
55
local function calculate_joltage(banks, size)
66
return fun.iter(banks)
77
:map(function(x)
8-
local largest = {}
98
local remaining = x
10-
fun.range(size - 1, 0):each(function(reserved)
11-
local it = fun.iter(remaining)
12-
local max = it:take(#remaining - reserved):max(x)
13-
local idx = it:index(max)
14-
remaining = it:drop(idx):totable()
15-
table.insert(largest, max)
16-
end)
9+
local largest = fun.range(size - 1, 0)
10+
:map(function(reserved)
11+
local it = fun.iter(remaining)
12+
local max = it:take(#remaining - reserved):max(x)
13+
local idx = it:index(max)
14+
remaining = it:drop(idx):totable()
15+
return max
16+
end)
17+
:totable()
1718
return tonumber(table.concat(largest))
1819
end)
1920
:sum()

0 commit comments

Comments
 (0)