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 Weave Strings Together

BQN, 8 bytesSBCS ∾⊒˜¨⊔○∾⊢ Run online! and parsing diagram The idea here is to build a list of groups, with group i containing the ith character of each string that has one, then join the group...

posted 3y ago by Marshall Lochbaum‭

Answer
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-04-25T01:37:12Z (almost 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 8 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>

```
∾⊒˜¨⊔○∾⊢
```

[Run online!](https://mlochbaum.github.io/BQN/try.html#code=V1Yg4oaQIOKIvuKKksucwqjiipTil4viiL7iiqIKCldWwqjin6gKICAia2lubyLigL8iY2luZW1hIuKAvyJtb3ZpZSIKICAiY29kZSLigL8iZ29sZiIKICAiSGki4oC/IiLigL8iVGhlcmUiCiAg4p+oIkV4cGxhbmF0aW9uIuKfqQogICJEeWFsb2cgQVBMIuKAvyJDdWx0aXZhdGlvbiLigL8iT3JjaGFyZCIK4p+p) and [parsing diagram](https://mlochbaum.github.io/BQN/try.html#code=4oi+4oqSy5zCqOKKlOKXi+KIvuKKog==&explain)

The idea here is to build a list of groups, with group `i` containing the `i`<sup>th</sup> character of each string that has one, then join the groups. The structure `∾ ⊒˜¨ ⊔○∾ ⊢` is a [train](https://mlochbaum.github.io/BQN/doc/train.html) of four functions: the last three form a 3-train and then [Join](https://mlochbaum.github.io/BQN/doc/join.html) (`∾`) is applied to the result.

```
∾⊒˜¨⊔○∾⊢
       ⊢  # Argument, unchanged
 ⊒˜¨      # Indices for each string
    ⊔○∾   # Join both and group
∾         # Join group result
```

The function `⊒˜¨` converts a list of strings such as `⟨"ab","cde"⟩` into indices `⟨0‿1,0‿1‿2⟩`. [Occurrence Count](https://mlochbaum.github.io/BQN/doc/selfcmp.html#occurrence-count) searches for cells of the right argument in the left argument, taking the first match and never matching a cell more than once. When applied with the same list as left and right argument using `˜`, it always matches each cell to itself as any previous cells that match it are used up. The result is the index of each match, giving sequential indices. Each (`¨`) simply applies this function to each string.

[Group](https://mlochbaum.github.io/BQN/doc/group.html) moves each character to the group with the specified index. For example, `0‿1‿0‿1‿2⊔"abcde"` is `⟨"ac","bd","e"⟩`. Since its arguments must be flat lists, not nested ones, it's applied as Group Over (`○`) Join, joining both arguments before applying. Instead of grouping and joining, it's also possible to sort by the indices with `⊒˜¨⍋⊸⊏○∾⊢`. But longer.