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 Beaver Code Decryption

BQN, 24 bytesSBCS {gβŠ”βΌπ•ŠΒ¨βŸ(1<β‰ )π•©βŠ”Λœβˆ§g←2|↕≠𝕩} Run online! {gβŠ”βΌπ•ŠΒ¨βŸ(1<β‰ )π•©βŠ”Λœβˆ§g←2|↕≠𝕩} { } # Block function π•Š with argument 𝕩 ≠𝕩 # Length of 𝕩 ...

posted 3y ago by Marshall Lochbaum‭

Answer
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-04-18T21:36:28Z (over 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 24 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>
```
{gβŠ”βΌπ•ŠΒ¨βŸ(1<β‰ )π•©βŠ”Λœβˆ§g←2|↕≠𝕩}
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=QkNF4oaQe+KIvuKXi/CdlYrCtPCdlaniipTLnDJ84oaV4omg8J2VqX3ijoriiqIgICAgICAgICAgIyBFbmNyeXB0CkJDROKGkHtn4oqU4oG88J2VisKo4o2fKDE84omgKfCdlaniipTLnOKIp2fihpAyfOKGleKJoPCdlal9ICAjIERlY3J5cHQKQkNEwqgg4p+oCiAgIiIKICAiQ1RZUk9QIgogICJFT1lDVE5OUFJJIgogICJSVU9FTkZTRUFGTVJESFQiCuKfqQ==)

```
{gβŠ”βΌπ•ŠΒ¨βŸ(1<β‰ )π•©βŠ”Λœβˆ§g←2|↕≠𝕩}
{                      }  # Block function π•Š with argument 𝕩
                     ≠𝕩   # Length of 𝕩
                    ↕     # Range: 0,1,…,n
                g←2|      # Mod 2: 0,1,0,…
               ∧          # Sort: 0,0,…,1,1,…
            π•©βŠ”Λœ           # Group 𝕩 by the above, splitting it in two
      ⍟(1<β‰ )              # If 1 is less than the length...
    π•ŠΒ¨                    #  ...call this function on each element
 gβŠ”βΌ                      # Ungroup as if grouped by 0,1,0,1,…
```

BQN doesn't directly offer a "zip" function for interleaving. However, its Undo (`⁼`) modifier can combine with [Group](https://mlochbaum.github.io/BQN/doc/group.html) to reverse an *un*interleaving. `βŠ”βΌ` isn't required [by the spec](https://mlochbaum.github.io/BQN/spec/inferred.html#undo) and dzaima/BQN doesn't support it; another 24-byte solution is `{(β‹βˆ˜β‹βŠΒ·βˆΎβ—‹π•ŠΒ΄π•©βŠ”Λœβˆ§)2|↕≠𝕩}⎊⊒`.

Using Undo means that the decoding program is similar to the encoding program given in the online link. The reason why decoding uses both normal and undone Group while encoding uses it only once is that for encoding the groups do not need to be mixed together, so [Join](https://mlochbaum.github.io/BQN/doc/join.html) (`∾`) can be used instead.