Comments on Make my number a set
Parent
Make my number a set
Natural to set
(set meaning an unordered collection with no duplicates, though answers may use and output lists instead)
Recently I was brainstorming what a language with only (arbitrarily nested) sets would be like. A number is represented with a set of that many elements. The elements need to be different, which leads to this definition:
Definition
- The set representation of $0$ is the empty set.
- The set representation of any other integer $n$ is the set of the set representations of all positive integers less than $n$, including zero.
- Negative, complex, or rational numbers do not need to be handled.
- Your full program or function is to convert from a positive integer to a set or list.
Examples
0 {}
1 {{}}
2 {{}, {{}}}
3 {{}, {{}}, {{}, {{}}}}
[JavaScript (V8)], 32 bytes …
3y ago
BQN, 7 6 bytesSBCS ``` ≢↑∘ …
3y ago
[APL (ngn/apl)], 6 bytes …
3y ago
[Python 3], 34 bytes …
3y ago
Japt, 3 bytes ``` ÆßX ``` …
3y ago
[Jelly], 3 bytes Ḷ߀ …
3y ago
[Haskell], 51 31 bytes Save …
3y ago
[Ruby], 27 bytes ```ruby - …
3y ago
Jq, 19 bytes ```python def …
3y ago
Ruby, 23 bytes ```ruby ->n …
3y ago
Post
Haskell, 51 31 bytes
Saved 20 bytes thanks to Hakerh400!
data S=S[S]
f i=S$map f[0..i-1]
S
is a recursive data structure, because sets of varying element types can't be represented with simple lists in Haskell.
0 comment threads