What are some good ways to represent a 2D array that extends in arbitrary length in both dimensions?
Working in Ruby.
What are some good ways to represent a 2D array that extends in arbitrary length in both dimensions?
Working in Ruby.
I think a hash is good:
{
  [0, 0] => "A1",
  [1, 0] => "B1",
  ...
  [0, 1] => "A2",
  [1, 1] => "B2",
  ...
}
Or, to make it a less transparent but more efficient, you may think of a way to map a pair of numbers to a single number using a pairing function along the lines suggested here, and use it as a key:
{
  0 => "A1",
  1 => "B1",
  ...
  2 => "A2",
  4 => "B2",
  ...
}