Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Make my number a set

Parent

Make my number a set

+7
−0

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 {{}, {{}}, {{}, {{}}}}
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+3
−0

Japt, 3 bytes

ÆßX

Try it online! (don't mind the -Q

This is Shaggy's solution.

ÆßX
Æ   Make a range [0, input) and map each number X:
 ß  Run this program again on
  X

Japt, 11 8 bytes

Saved 3 bytes thanks to Shaggy! (Shaggy also has a 3-byter ready)

gA=_o mA

Try it online!

This is practically a port of Razetime's answer, which you should upvote!

gA=_o mA
g        Apply the following function to the input
 A=      It's a recursive function, so assign it to the variable A
   _o    Make a range [0, Z), where Z is the input
      mA And map every number in that range to A again
History
Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

Welcome (4 comments)
Welcome
Shaggy‭ wrote almost 3 years ago

Welcome to Japt :) You can save 3 bytes here using one of Japt's own variables (i.e., an uppercase letter) to assign the function to, avoiding the need to switch in & out of JS. But you can get even shorter by using Japt's built-in recursion (ß) with o@ßX which can be further shortened with a shortcut to just ÆßX, tying you with Jelly.

user‭ wrote almost 3 years ago

Shaggy‭ Wow! Are you sure you don't want to write that last one as your own answer?

Shaggy‭ wrote almost 3 years ago

Not at all, @user; it's just your solution golfed down further. And I'd always much rather help out a newcomer to Japt to the rep I might get from posting something myself.

user‭ wrote almost 3 years ago

Shaggy‭ Alright, thanks!