# Tips for golfing in BQN

What general tips do you have for golfing in BQN? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to BQN (e.g. "remove comments" is not an answer).

Please post one tip per answer.

At the moment of writing, the official BQN site is the most comprehensive resource for learning BQN. BQN is the Language of the Month for December 2021; you can find some more information and resources on the LotM page.

Additional resources:

• Maybe link to BQNcrate? Also, many tips for golfing in APL and J may be relevant.
– Adám
Dec 1, 2021 at 1:57
• Does "golfing in BQN" mean "reduce the amount of uneaten bacon" or "reduce the weight gained from eating said bacon"? Dec 1, 2021 at 1:58
• @Adám Good idea, added. Dec 1, 2021 at 2:03
• @tjjfvi I thought it was "playing golf on a bacon field, or dressed with bacon".. I don't know if the language was named on purpose, but I came here for this pun ^^ Dec 1, 2021 at 12:37

# Use ⊒˜ instead of ↕∘≠

Suggested by Marshall

⊒(progressive index of) consumes indices given any array, providing a range of the array's size when applied with selfie. You can save a byte by using it in any place instead of ↕∘≠.

Try it!

# BQN's combinators

BQN allows Lisp style functional programming and hence comes with its own set of combinator symbols. Some basic patterns can be simplified using combinators instead of trains:

Lambda Train Combinator
{𝕩 F 𝕩} ⊢ F ⊢ F˜
{F G 𝕩} F G F∘G, F○G
{𝕩 F (G 𝕩)} ⊢ F G F⟜G
{(F 𝕩) G 𝕩} F G ⊢ F⊸G
{𝕩 F 𝕨} ⊢ F ⊣ F˜(See: this APL tip, replace ⍨ with ˜)
{F 𝕨 G 𝕩} F G F∘G
{(G 𝕨) F (G 𝕩)} G F G F○G
{(𝕨 F 𝕩) G (𝕨 H 𝕩)} F G H F⊸G⟜H

You can use the shorter one between the train and the combinator versions wherever necessary, and sometimes in conjunction.

For a more visual explanation of the combinators, see here

# Don't forget about ¬

BQN doesn't have increment and decrement primitives, which means you're often spending two bytes on 1+, or potentially three on ¯1+. Sometimes ¬ can help:

• Monadic ¬𝕩 ("not") is logical negation, but it's actually implemented as 1-𝕩.
• Dyadic 𝕨¬𝕩 ("span") is even more interesting: it's 1+𝕨-𝕩.

These can save bytes under some specific circumstances. For instance, if you need to decrement the result of an expression, -¬aFb is shorter than ¯1+aFb. Similarly, a¬-b is shorter than a+1+b, and a-¬b is shorter than a-1+b. If you need to multiply a number by 2 and add 1, ¬⟜- is equivalent to 1+2×⊢.

This is similar to the use of ~ in C-like languages (although there, ~x is -x-1, not 1-x).