How do you get row back out of n?
local n = row * cols + col
local c = n % cols
local r = ?
How do you get row back out of n?
local n = row * cols + col
local c = n % cols
local r = ?
Using some simple arithmetic...
You have
n = rows * cols + col
subtract col
from both sides
n - col = rows * cols
divide by cols
on both sides
(n - col) / cols = rows
Assuming col < cols
holds, you could do it with integer division as rows = n / cols
.