The natural numbers including 0 are formally defined as sets, in the following way:
- Number 0 is defined as the empty set, {}
- For n ≥ 0, number n+1 is defined as n ∪ {n}.
As a consequence, n = {0, 1, ..., n-1}.
The first numbers, defined by this procedure, are:
- 0 = {}
- 1 = {{}}
- 2 = {{}, {{}}}
- 3 = {{}, {{}}, {{}, {{}}}}
Challenge
Given n
, output its representation as a set.
Rules
The output can consistently use any bracket character such as {}
, []
, ()
or <>
. Arbitrary characters (such as 01
) are not allowed.
Instead of a comma as above, the separator can be any punctuation sign; or it may be inexistent.
Spaces (not newlines) may be included arbitrarily and inconsistently.
For example, number 2 with square brackets and semicolon as separator is [[]; [[]]]
, or equivalently [ [ ]; [ [ ] ] ]
, or even [ [ ] ;[ []]]
The order in which elements of a set are specified doesn't matter. So you can use any order in the representation. For example, these are some valid outputs for 3
:
{{},{{}},{{},{{}}}}
{{{}},{{},{{}}},{}}
{{{}},{{{}},{}},{}}
You can write a program or function. Output may be a string or, if using a function, you may return a nested list or array whose string representation conforms to the above.
Test cases
0 -> {}
1 -> {{}}
2 -> {{},{{}}}
3 -> {{},{{}},{{},{{}}}}
4 -> {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}
5 -> {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}
6 -> {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}}
7 -> {{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}},{{},{{}},{{},{{}}},{{},{{}},{{},{{}}}}}}}}