63
3
In: Enough memory and a positive integer N
Out: N-dimensional N^N array filled with N, where N^N means N terms of N-by-N-by-N-by...
Examples:
1: [1]
which is a 1D array (a list) of length 1, containing a single 1
2: [[2,2],[2,2]]
which is a 2D array (a table) with 2 rows and 2 columns, filled with 2s
3: [[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]]]
which is a 3D array (a cube) with 3 layers, 3 rows, and 3 columns, filled with 3s
4: [[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]],[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]],[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]],[[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]],[[4,4,4,4],[4,4,4,4],[4,4,4,4],[4,4,4,4]]]]
5 and 6: Please see one of the answers.
If our language does not support arrays, what would be an acceptable output format? – Okx – 2017-02-28T16:54:55.953
@Okx JSON, or any other unambiguous array notation. – Adám – 2017-02-28T16:55:48.133
18Since "Enough memory" is part of the input, I want to see an answer that controls a robot to actually take the memory as input and plug it in before using it. – user2357112 supports Monica – 2017-02-28T19:05:56.477
1Do all the arrays need to be distinct objects? – Neil – 2017-03-01T00:25:55.880
1@user2357112 I think that's more of a precondition type issue. I doubt the op actually expects the function to accept memory as input. – user64742 – 2017-03-01T04:31:19.773
2@TheGreatDuck Correct, but I'm pretty sure user2357112 meant it as a joke. – Adám – 2017-03-01T05:47:09.340
@Neil I don't understand. Can you elaborate? – Adám – 2017-03-01T05:50:15.637
Take the case N = 3. Am I allowed to write (unrolled)
a = 3; a = [a, a, a]; a = [a, a, a]; a = [a, a, a];
or must I writea11 = [3, 3, 3]; a12 = [3, 3, 3]; a13 = [3, 3, 3]; a1 = [a11, a12, a13]; /* etc. for a2 and a3 */ a = [a1, a2, a3];
? – Neil – 2017-03-01T09:55:01.200@Neil Ah, they are pointers, so the if one sets the very first element of the first a to 2, all the elements of a become 2, whereas that isn't the case for the second a. The first is fine too, if it isn't too much work, I'd be interested in seeing both for comparison. – Adám – 2017-03-01T09:58:58.160
start="5">
@sergiol Now that there are plenty of answers, you can just use one of the Try it Online! links to generate the desired outputs. – Adám – 2017-08-21T20:21:23.590
can I have a trailing comma at the end of the answer like "[1]," or "[[2,2],[2,2]]," – JoshM – 2018-06-05T19:37:33.013
@JoshM You're supposed to return/output an array. – Adám – 2018-06-05T19:46:01.060
@Adám nvm I figured it out – JoshM – 2018-06-05T20:18:01.810
The hastebin links seem to be broken. They redirect me to the main site – Conor O'Brien – 2018-06-22T20:51:03.243