[Question]
  [
### Definition
Define the **n**th array of the CURR sequence as follows.
1. Begin with the singleton array **A = [n]**.
2. For each integer **k** in **A**, replace the entry **k** with **k** natural numbers, counting up from **1** to **k**.
3. Repeat the previous step **n - 1** more times.
For example, if **n = 3**, we start with the array **[3]**.
We replace **3** with **1, 2, 3**, yielding **[1, 2, 3]**.
We now replace **1**, **2**, and **3** with **1**; **1, 2** and **1, 2, 3** (resp.), yielding **[1, 1, 2, 1, 2, 3]**.
Finally, we perform the same replacements as in the previous step for all six integers in the array, yielding **[1, 1, 1, 2, 1, 1, 2, 1, 2, 3]**. This is the third CURR array.
### Task
Write a program of a function that, given a strictly positive integer **n** as input, computes the **n**th CURR array.
The output has to be a *flat* list of some kind (and array returned from a function, a string representation of your language's array syntax, whitespace-separated, etc.).
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"). May the shortest code in bytes win!
### Test cases
```
 1 -> [1]
 2 -> [1, 1, 2]
 3 -> [1, 1, 1, 2, 1, 1, 2, 1, 2, 3]
 4 -> [1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4]
 5 -> [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5]
 6 -> [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, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 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]
```
  
[Answer]
## Jelly, 3 bytes
```
R¡F
```
[Try it online](http://jelly.tryitonline.net/#code=UsKhRg&input=&args=Mw)
## Explanation
```
R¡F    Argument n
R      Yield range [1..n]
 ¡     Repeat n times
  F    Flatten the result
```
[Answer]
## Python, 50 bytes
```
lambda i:eval("[i "+"for i in range(1,i+1)"*i+"]")
```
Scope abuse! For example, for `i=3`, the string to be evaluated expands to. 
```
[i for i in range(1,i+1)for i in range(1,i+1)for i in range(1,i+1)]
```
Somehow, despite using the function input variable `i` for everything, Python distinguishes each iteration index as belonging to a separate scope as if the expression were
```
[l for j in range(1,i+1)for k in range(1,j+1)for l in range(1,k+1)]
```
with `i` the input to the function.
[Answer]
## 05AB1E, ~~6~~ 3 bytes
```
DFL
```
**Explained**
```
D     # duplicate input
 F    # input times do
  L   # range(1,N)
```
[Try it online](http://05ab1e.tryitonline.net/#code=REZM&input=Mw)
Saved 3 bytes thanks to @Adnan
[Answer]
## [Retina](https://github.com/mbuettner/retina), 33 bytes
```
$
$.`$*0
+%(M!&`1.*(?=0)|^.+
O`.+
```
Input and output in unary.
[Try it online!](http://retina.tryitonline.net/#code=JAokLmAkKjAKKyUoTSEmYDEuKig_PTApfF4uKwpPYC4r&input=MTEx)
Even though I didn't use the closed form for the related challenge, adapting this answer was surprisingly tricky.
[Answer]
## Python 2, 82 bytes
```
lambda n:[1+bin(i)[::-1].find('1')for i in range(1<<2*n-1)if bin(i).count('1')==n]
```
This isn't the shortest solution, but it illustrates an interesting method:
* Write down the first `2^(2*n-1)` numbers in binary
* Keep those with exactly `n` ones
* For each number, count the number of trailing zeroes, and add 1.
[Answer]
## Actually, 9 bytes
```
;#@`♂RΣ`n
```
[Try it online!](http://actually.tryitonline.net/#code=OyNAYOKZglLOo2Bu&input=Mw)
Explanation:
```
;#@`♂RΣ`n
;#@        dupe n, make a singleton list, swap with n
   `♂RΣ`n  call the following function n times:
    ♂R       range(1, k+1) for k in list
      Σ      concatenate the ranges
```
Thanks to Leaky Nun for a byte, and inspiration for another 2 bytes.
[Answer]
## C#, 128 Bytes
```
List<int>j(int n){var l=new List<int>(){n};for(;n>0;n--)l=l.Select(p=>Enumerable.Range(1,p)).SelectMany(m=>m).ToList();return l;
```
[Answer]
# APL, 11 bytes
```
{∊⍳¨∘∊⍣⍵+⍵}
```
Test:
```
      {∊⍳¨∘∊⍣⍵+⍵} 3
1 1 1 2 1 1 2 1 2 3
```
Explanation:
* `+⍵`: starting with `⍵`,
* `⍣⍵`: do the following `⍵` times:
	+ `⍳¨∘∊`: flatten the input, and then generate a list [1..N] for each N in the input
* `∊`: flatten the result of that
[Answer]
# J, 18 bytes
```
([:;<@(1+i.)"0)^:]
```
Straight-forward approach based on the process described in the challenge.
## Usage
```
   f =: ([:;<@(1+i.)"0)^:]
   f 1
1
   f 2
1 1 2
   f 3
1 1 1 2 1 1 2 1 2 3
   f 4
1 1 1 1 2 1 1 1 2 1 1 2 1 2 3 1 1 1 2 1 1 2 1 2 3 1 1 2 1 2 3 1 2 3 4
```
## Explanation
```
([:;<@(1+i.)"0)^:]  Input: n
                 ]  Identity function, gets the value n
(     ...     )^:   Repeat the following n times with an initial value [n]
      (    )"0        Means rank 0, or to operate on each atom in the list
         i.           Create a range from 0 to that value, exclusive
       1+             Add 1 to each to make the range from 1 to that value
    <@                Box the value
 [:;                  Combine the boxes and unbox them to make a list and return
                    Return the final result after n iterations
```
[Answer]
## CJam, 14 bytes
```
{_a\{:,:~:)}*}
```
[Test it here.](http://cjam.aditsu.net/#code=3%0A%0A%7B_a%5C%7B%3A%2C%3A~%3A)%7D*%7D%0A%0A~p&input=3)
### Explanation
```
_a   e# Duplicate N and wrap it in an array.
\    e# Swap with other copy of N.
{    e# Do this N times...
  :, e#   Turn each x into [0 1 ... x-1].
  :~ e#   Unwrap each of those arrays.
  :) e#   Increment each element.
}*
```
[Answer]
## Mathematica, ~~27~~ 26 bytes
*1 byte saved with some inspiration from Essari's answer.*
```
Flatten@Nest[Range,{#},#]&
```
Fairly straightforward: for input `x` we start with `{x}` and then apply the `Range` to it `x` times (`Range` is `Listable` which means that it automatically applies to the integers inside arbitrarily nested lists). At the end `Flatten` the result.
[Answer]
## Clojure, 59 bytes
```
(fn[n](nth(iterate #(mapcat(fn[x](range 1(inc x)))%)[n])n))
```
Explanation:
Really straight forward way to solve the problem. Working from the inside out:
```
(1) (fn[x](range 1(inc x))) ;; return a list from 1 to x
(2) #(mapcat (1) %)         ;; map (1) over each item in list and flatten result
(3) (iterate (2) [n])       ;; call (2) repeatedly e.g. (f (f (f [n])))
(4) (nth (3) n))            ;; return the nth value of the iteration
```
[Answer]
# Python 3, ~~75~~ 74 bytes
```
def f(k):N=[k];exec('A=N;N=[]\nfor i in A:N+=range(1,i+1)\n'*k+'print(N)')
```
This is just a straightforward translation of the problem description to code.
Edit: Saved one byte thanks to @Dennis.
[Answer]
## R, ~~60~~ 49 bytes
Pretty straightforward use of `unlist` and `sapply`.
```
y=x=scan();for(i in 1:x)y=unlist(sapply(y,seq));y
```
Thanks to @MickyT for saving 11 bytes
[Answer]
## php 121
Not really very much in the way of tricks behind this one.
Flattening an array in php isn't short so it's necessary to build it flat in the first place
```
<?php for($a=[$b=$argv[1]];$b--;)$a=array_reduce($a,function($r,$v){return array_merge($r,range(1,$v));},[]);print_r($a);
```
[Answer]
## Haskell, 33 bytes
```
f n=iterate(>>= \a->[1..a])[n]!!n
```
Thanks to nimi for saving a byte.
A pointfree version is longer (35 bytes):
```
(!!)=<<iterate(>>= \a->[1..a]).pure
```
[Answer]
## JavaScript (Firefox 30-57), ~~63~~ 60 bytes
```
f=n=>eval(`[${`for(n of Array(n+1).keys())`.repeat(n--)}n+1]`)
```
Port of @xnor's Python answer.
[Answer]
# Pyth, 8 bytes
```
usSMGQ]Q
```
[Try it online!](http://pyth.herokuapp.com/?code=usSMGQ%5DQ&test_suite=1&test_suite_input=3&debug=0)
```
usSMGQ]Q   input as Q
u    Q     repeat for Q times,
      ]Q   starting as [Q]:
  SMG          convert each number in the array to its range
 s             flatten
           then implicitly prints the result.
```
[Answer]
# Jelly, 7 bytes
Quick, before Dennis answers (jk)
```
WR€F$³¡
```
[Try it online!](http://jelly.tryitonline.net/#code=V1LigqxGJMKzwqE&input=Mw&args=Mw)
```
WR€F$³¡  Main monadic chain. Argument: z
W        Yield [z].
     ³¡  Repeat the following z times:
 R€          Convert each number in the array to the corresponding range.
   F         Flatten the array.
```
[Answer]
## F# , 63 bytes
```
fun n->Seq.fold(fun A _->List.collect(fun k->[1..k])A)[n]{1..n}
```
Returns an anonymous function taking n as input.
Replaces every entry k in A with [1..k], repeats the process n times, starting with A = [n].
[Answer]
# Swift 3, 58 Bytes
Meant to run directly in the a playground, with n set to the input:
```
var x=[n];for i in 0..<n{x=x.reduce([]){$0+[Int](1...$1)}}
```
Ungolfed, with most short hand notation reverted:
```
let n = 3 //input
var x: Array<Int> = [n]
for i in 0..<n {
    x = x.reduce(Array<Int>[], combine: { accumulator, element in
        accumulator + Array<Int>(1...element)
    })
}
```
[Answer]
# Java, 159 Bytes
**Procedure**
```
int[] q(int y){int z[]=new int[]{y};for(int i=0;i<y;i++){int d=0,a=0;for(int c:z)d+=c;int[]r=new int[d];for(int c:z)for(int j=0;j<c;)r[a++]=++j;z=r;}return z;}
```
**Usage**
```
public static void main(String[] args){String out = "["; int [] b = q(6);for(int c:b)out+=c+", ";System.out.println(out+"]");}
public static int[] q(int y){int z[]=new int[]{y};for(int i=0;i<y;i++){int d=0,a=0;for(int c:z)d+=c;int[]r=new int[d];for(int c:z)for(int j=0;j<c;)r[a++]=++j;z=r;}return z;}
```
*Sample output:*
```
[1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5, 1, 1, 1, 2, 1, 1, 2, 1, 2, 3, 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 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, ]
```
[Answer]
## Python 2, ~~69~~ ~~68~~ 66 bytes
```
def f(n):a=[n];exec'a=sum([range(1,i+1)for i in a],[]);'*n;print a
```
Edit: Saved 1 byte thanks to @xnor. Saved 2 bytes thanks to @Dennis♦.
[Answer]
# Bash + GNU utilities, 49
* 1 byte saved thanks to @Dennis.
Piped recursive functions FTW!
```
f()((($1))&&xargs -l seq|f $[$1-1]||dd)
f $1<<<$1
```
`n` is passed on the command-line. Output is newline-separated.
The use of `dd` causes statistics to be sent to STDERR. I think this is OK, but if not, `dd` can be replaced with `cat` at a cost of 1 extra byte.
[Answer]
# [Ruby](https://www.ruby-lang.org/), 44 bytes
A simple recursive approach.
```
->n,a=[n]{n>0?F[n-1,a.flat_map{[*1.._1]}]:a}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72kqDSpcsEiN9ulpSVpuhY3dXTt8nQSbaPzYqvz7Azs3aLzdA11EvXSchJL4nMTC6qjtQz19OINY2tjrRJrIXqWFSi4RRvHQjgLFkBoAA)
[Answer]
# Perl 5, 53 bytes
A subroutine:
```
{($i)=@_;for(1..$i){my@c;push@c,1..$_ for@_;@_=@c}@_}
```
See it in action as
```
perl -e'print "$_ " for sub{($i)=@_;for(1..$i){my@c;push@c,1..$_ for@_;@_=@c}@_}->(3)'
```
[Answer]
## Ruby, 61 bytes
```
def f(n);a=[n];n.times{a=a.map{|i|(1..i).to_a}.flatten};a;end
```
[Answer]
# PHP, ~~100~~ 98 bytes
Run with `php -r '<code>' <n>`.
```
for($a=[$n=$argv[1]];$n--;$a=$b)for($b=[],$k=0;$c=$a[$k++];)for($i=0;$i++<$c;)$b[]=$i;print_r($a);
```
In each iteration create a temporary copy looping from 1..(first value removed) until `$a` is empty.
---
These two are still and will probably remain at 100 bytes:
```
for($a=[$n=$argv[1]];$n--;)for($i=count($a);$i--;)array_splice($a,$i,1,range(1,$a[$i]));print_r($a);
```
In each iteration loop backwards through array replacing each number with a range.
```
for($a=[$n=$argv[1]];$n--;)for($i=$c=0;$c=$a[$i+=$c];)array_splice($a,$i,1,range(1,$c));print_r($a);
```
In each iteration loop through array increasing index by previous number and replacing each indexed element with a range
[Answer]
# [Japt](https://github.com/ETHproductions/japt) [`-mh`](https://codegolf.meta.stackexchange.com/a/14339/), 4 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
N=cõ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&flags=LW1o&code=Tj1j9Q&input=Mw)
[Answer]
# [Perl 5](https://www.perl.org/) + `-p`, 28 bytes
```
eval's/\d+/@{[1..$&]}/g;'x$_
```
[Try it online!](https://dom111.github.io/code-sandbox/#eyJsYW5nIjoid2VicGVybC01LjI4LjEiLCJjb2RlIjoiZXZhbCdzL1xcZCsvQHtbMS4uJCZdfS9nOyd4JF8iLCJhcmdzIjoiLXAiLCJpbnB1dCI6IjFcbjJcbjNcbjRcbjVcbjYifQ==)
]