Hacker News new | ask | show | jobs
by drbaba 1062 days ago
> If you have a two dimensional array A (1..N X 1..M), then flattening it becomes A[i][j] = flat[i + (j-1) * N]

> When flattening A (0..N-1 X 0..M-1) A[i][j] becomes flat[i + N * j].

To play the devil’s advocate a bit: Both cases above has the same number of “-1” offsets; the question is whether it is in the indexing or in the bounds. In the 0-indexed case, i goes from 0 to N-1 instead of from 1 to N, and this happens for every array dimension.