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

66%
+2 −0
Challenges Length of a Sumac Sequence

BQN, 15 bytesSBCS {𝕨(1+βŠ’π•Š-)βŸœπ•©βŸ>0} Run online! A block function that takes $t_1$ as the left argument 𝕨 and $t_2$ as the right argument 𝕩. In BQN, π•Š indicates recursion on the current block ...

posted 3y ago by Marshall Lochbaum‭

Answer
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-04-24T20:46:18Z (about 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 15 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>

```
{𝕨(1+βŠ’π•Š-)βŸœπ•©βŸ>0}
```

[Run online!](https://mlochbaum.github.io/BQN/try.html#code=U1Mg4oaQIHvwnZWoKDEr4oqi8J2Vii0p4p+c8J2VqeKNnz4wfQoKU1PCtMKo4p+oICMgRm9sZCAowrQpIHRvIGFwcGx5IHRvIGxpc3RzCiAg4p+oMTIwLDcx4p+pCiAg4p+oMTAxLDQy4p+pCiAg4p+oNTAwLDQ5OeKfqQogIOKfqDM4Nywx4p+pCiAg4p+oMywtMTI44p+pCiAg4p+oLTIsM+KfqQogIOKfqDMsMuKfqQrin6k=)

A block function that takes $t_1$ as the left argument `𝕨` and $t_2$ as the right argument `𝕩`. In BQN, `π•Š` indicates [recursion](https://mlochbaum.github.io/BQN/doc/block.html#self-reference) on the current block function. Inside the function the idea is just to return 0 if `𝕨≀0` and otherwise advance the sequence by one, recurse, and add one to the resulting sequence length.

```
{𝕨(1+βŠ’π•Š-)βŸœπ•©βŸ>0}
             0   # Default result of 0
 𝕨         ⍟>    # If 𝕨>0:
  (     )βŸœπ•©      # Use 𝕩 as right arg (left is still 𝕨)
     ⊒ -         # Right argument ⊒ and difference -
      π•Š          # Recurse
   1+            # Add one
```

The unrelated 0s for sequence length and minimum `𝕨` are combined by making 0 the right argument and using Repeat (`⍟`). With 0 repetitions, Repeat will return the right argument 0, and with 1 repetition, it will call the operand function, which immediately replaces 0 with `𝕩` using [After](https://mlochbaum.github.io/BQN/tutorial/combinator.html#before-and-after) (`𝕩` is a number, so it acts as a constant function).