File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -5,15 +5,15 @@ local util = require "util"
55local 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 ()
You can’t perform that action at this time.
0 commit comments