Joe, 5 3 bytes (+2 or +3 for -t
flag)
Well, apparently I didn't utilize the full potential of Joe. This was possible back when I first posted this.
\AR
Here, R
gives the range from 0 to n, exclusive. Then \A
takes successive prefixes of it (A
is the identity function). Examples:
With -t
flag (note: this is now the standard output even without the flag):
(\AR)5
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
\AR5
0
0 1
0 1 2
0 1 2 3
0 1 2 3 4
\AR2
0
0 1
\AR1
0
\AR0
Without it:
\AR5
[[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]]
(\AR)5
[[0], [0, 1], [0, 1, 2], [0, 1, 2, 3], [0, 1, 2, 3, 4]]
\AR2
[[0], [0, 1]]
\AR1
[[0]]
\AR0
[]
The rules got changed a bit. My old code didn't behave correctly with N =0. Also, now output could be just a nested list, so -t
can be dropped.
1R1+R
Now, Rn
gives a range from 0 to n, exclusive. If given 0, it returns an empty list. 1+
adds 1 to every element of that range. 1R
maps the values to ranges from 1 to x. Empty liats, when mapped, return empty lists.
Example output:
1R1+R0
[]
1R1+R5
[[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]]
Update: I just noticed something. The function automatically maps to rank 0 elements. The following example is run with -t
flag.
1R1+R3 5 8
1
1 2
1 2 3
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
Old: 5 bytes (with the -t
flag)
1R1R
This is an anonymous function which takes in a number, creates a list from 1 to N (1Rn
) and maps those values to the preceding range, giving a range from 1 to x for each item of range 1 to N.
The -t
flag gives output as a J-like table.
1R1R5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Note : the language is very new and not complete, but the latest version was released before this challenge.
Can the output be a nested list of numbers? – seequ – 2015-03-12T05:39:31.920
What should be the behavior for n=0, and for n>9? – freekvd – 2015-03-12T18:55:39.633
@Sieg Sure, as long as the output is correct. – Tan WS – 2015-03-13T00:57:08.980
@freekvd for 0 there is no output, for n>9 no special formatting required – Tan WS – 2015-03-13T01:00:19.673
Ah darn, you broke my submission. Fixing ASAP – seequ – 2015-03-13T05:54:17.417
Can you include an example larger than 10 we can see how two double-digit numbers should look together? – FlipTack – 2017-01-21T08:24:34.543