Skip to content

Commit 4ab9254

Browse files
committed
2025: Optimize
1 parent d593e2e commit 4ab9254

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

2025/src/day03_spec.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ 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+
remaining = it:drop(it:index(max)):totable()
14+
return max
15+
end)
16+
:totable()
1717
return tonumber(table.concat(largest))
1818
end)
1919
:sum()

0 commit comments

Comments
 (0)