Write a program or function that, given an integer n
, construct an array with n
dimensions of n
length, where each element is an identifier of its own coordinates. That is, starting with one array, populate it with n
arrays, where each of those contain n
more arrays, up to a depth of n-1
. The elements of the deepest arrays are the coordinates describing where they are in the full array.
Some examples in case my explanation was confusing.
n = 1
["1"]
n = 2
[
["11", "12"],
["21", "22"]
]
n = 3
[
[
["111","112","113"],
["121","122","123"],
["131","132","133"]
],
[
["211","212","213"],
["221","222","223"],
["231","232","233"]
],
[
["311","312","313"],
["321","322","323"],
["331","332","333"]
]
]
Here, "321" means it is the 1st element of the 2nd element of the 3rd array.
Rules:
- Coordinates and dimension (
n
) can be either 0 or 1 indexed - You may assume
n
is single digit, below 10 for both indexing options to prevent ambiguous outputs - IO is flexible.
- In particular, coordinates can be arrays, strings etc. as long as they are clear. "321" => [3,2,1]
- Output can be integers in base 10 with or without leading zeroes.
- Coordinates can be in reverse order if you wish, as long as it is consistent. "321" => "123"
- Output doesn't necessarily have to be an array structure in your language. As long as there's clear distinct markers for the start of an array, end of an array and for separating elements.
- The output for
n=1
can just be 1 - If your output is atypical, make sure to explain the format.
- This is code-golf so the shortest solution in each language wins!
data L a = L [L a] | E a
. \$\endgroup\$Int -> [String]
orInt -> [[String]]
and so on, depending on what the input is \$\endgroup\$