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 Create an Alphabet Diamond

BQN, 19 bytesSBCS ' '+32⊸<⊸×+⌜˜⌽⊸⌊↕59 Run online! This uses the whitespace allowance, padding by four spaces on all sides to make the arithmetic work better. It can be adjusted by replacing...

posted 3y ago by Marshall Lochbaum‭

Answer
#1: Initial revision by user avatar Marshall Lochbaum‭ · 2021-04-20T00:21:46Z (over 3 years ago)
# [BQN](https://mlochbaum.github.io/BQN/), 19 bytes<sup>[SBCS](https://github.com/mlochbaum/BQN/blob/master/commentary/sbcs.bqn)</sup>
```
' '+32⊸<⊸×+⌜˜⌽⊸⌊↕59
```
[Run online!](https://mlochbaum.github.io/BQN/try.html#code=JyAnKzMy4oq4POKKuMOXK+KMnMuc4oy94oq44oyK4oaVNTk=)

This uses the whitespace allowance, padding by four spaces on all sides to make the arithmetic work better. It can be adjusted by replacing `↕59` with `4+↕51` at the cost of two characters.

BQN has no built-in idea of the alphabet, but it has a nice system for Unicode [character arithmetic](https://mlochbaum.github.io/BQN/tutorial/expression.html#character-arithmetic). This solution depends on the length 26 of the alphabet, and the distance 33 (`'A'-' '`) from space to the start. Fortunately these are close together. We will build a matrix of numbers that goes from 0, for `' '`, at the corners to `33+26-1`, or 58, at the center, then bring all numbers below 33 to 0. At the middle of each edge we get 29, leaving 4 spaces before `'A'`. [Before](https://mlochbaum.github.io/BQN/tutorial/combinator.html#before-and-after) plays a big role here.

```
' '+32⊸<⊸×+⌜˜⌽⊸⌊↕59
                ↕59   # Range            0...58
             ⌽        # Reverse:         58...0
              ⊸⌊      #  Before Minimum: 0…29…0
          +⌜          # Addition table
            ˜         #  with itself
    32⊸<              # More than 32
        ⊸×            #  times the original
' '+                  # Add to space
```

Another 21-character "exact" solution is `(+⌜˜⊏-∘≠↑'A'+⍷)⌽⊸⌊↕51`. Now `'A'` is used as the basis and spaces come from fill elements in Take (`↑`), so it will work for any starting character.