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

Post History

77%
+5 −0
Challenges Make my number a set

BQN, 7 6 bytesSBCS ≢↑∘⊢´↕ Run online! The less-golfed version {↑⍟𝕩⟨⟩} is more readable: it applies Prefixes (↑) the given number of times to the empty list ⟨⟩ and… that's it. (Suffixes also wo...

posted 3y ago by Marshall Lochbaum‭  ·  edited 3y ago by Marshall Lochbaum‭

Answer
#2: Post edited by user avatar Marshall Lochbaum‭ · 2021-04-28T12:25:19Z (almost 3 years ago)
  • # [BQN](https://mlochbaum.github.io/BQN/), 7 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>
  • ```
  • {↑⍟𝕩⟨⟩}
  • ```
  • [Run online!](https://mlochbaum.github.io/BQN/try.html#code=U2V0IOKGkCB74oaR4o2f8J2VqeKfqOKfqX0KCuKJjcuY4p+cKFNldMKoKSDihpU0)
  • Stumbled on this one a little while ago. This function applies [Prefixes](https://mlochbaum.github.io/BQN/doc/prefixes.html) the given number of times to the empty list `⟨⟩` and… that's it. (Suffixes also works, placing elements in the opposite order). The reason this works is that a prefix of a set-number is also a set-number, so that the values of the prefixes for `n` range from the empty prefix `0` to the complete prefix `n`. This list is defined to be `n+1`.
  • # [BQN](https://mlochbaum.github.io/BQN/), <strike>7</strike> 6 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>
  • ```
  • ≢↑∘⊢´↕
  • ```
  • [Run online!](https://mlochbaum.github.io/BQN/try.html#code=U2V0IOKGkCB74oaR4o2f8J2VqeKfqOKfqX0KU2V0IOKGqSDiiaLihpHiiJjiiqLCtOKGlQoK4omNy5jin5woU2V0wqgpIOKGlTQ=)
  • The less-golfed version `{↑⍟𝕩⟨⟩}` is more readable: it applies [Prefixes](https://mlochbaum.github.io/BQN/doc/prefixes.html) (`↑`) the given number of times to the empty list `⟨⟩` and… that's it. (Suffixes also works, placing elements in the opposite order). The reason this works is that a prefix of a set-number is also a set-number, so that the values of the prefixes for `n` range from the empty prefix `0` to the complete prefix `n`. This list is defined to be `n+1`.
  • The golfed version uses [Fold](https://mlochbaum.github.io/BQN/doc/fold.html) (`´`) and some other tricks to turn the computation into a 3-[train](https://mlochbaum.github.io/BQN/doc/train.html): something that doesn't work well with Repeat (`⍟`) because the number needs to be an operand.
  • ```
  • ≢↑∘⊢´↕
  • ↕ # Range: a list with length given by the argument
  • ≢ # Shape: an empty list as the argument has no axes
  • ´ # Fold over the range, starting with the shape
  • ↑ # Prefixes
  • ∘⊢ # Of the right argument
  • ```
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-04-28T00:53:36Z (almost 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 7 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>

```
{↑⍟𝕩⟨⟩}
```

[Run online!](https://mlochbaum.github.io/BQN/try.html#code=U2V0IOKGkCB74oaR4o2f8J2VqeKfqOKfqX0KCuKJjcuY4p+cKFNldMKoKSDihpU0)

Stumbled on this one a little while ago. This function applies [Prefixes](https://mlochbaum.github.io/BQN/doc/prefixes.html) the given number of times to the empty list `⟨⟩` and… that's it. (Suffixes also works, placing elements in the opposite order). The reason this works is that a prefix of a set-number is also a set-number, so that the values of the prefixes for `n` range from the empty prefix `0` to the complete prefix `n`. This list is defined to be `n+1`.