Code for the Advent of Code event
aoc advent-of-code
at rust 34 lines 619 B view raw
1local grid = {} 2 3local _grid = {} 4 5function grid.init(value) 6 for x = 0, 999 do 7 if type(_grid[x]) ~= "table" then _grid[x] = {} end 8 for y = 0, 999 do 9 _grid[x][y] = value 10 end 11 end 12end 13 14function grid.apply(func, startx, endx, starty, endy) 15 for x = startx, endx do 16 for y = starty, endy do 17 _grid[x][y] = func(_grid[x][y]) 18 end 19 end 20end 21 22function grid.accum(start, func) 23 local result = start 24 25 for x = 0, 999 do 26 for y = 0, 999 do 27 result = func(result, _grid[x][y]) 28 end 29 end 30 31 return result 32end 33 34return grid