9
\$\begingroup\$

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:

\$\endgroup\$
4
  • \$\begingroup\$ Maybe link to BQNcrate? Also, many tips for golfing in APL and J may be relevant. \$\endgroup\$
    – Adám
    Dec 1 '21 at 1:57
  • 2
    \$\begingroup\$ Does "golfing in BQN" mean "reduce the amount of uneaten bacon" or "reduce the weight gained from eating said bacon"? \$\endgroup\$
    – tjjfvi
    Dec 1 '21 at 1:58
  • \$\begingroup\$ @Adám Good idea, added. \$\endgroup\$
    – Bubbler
    Dec 1 '21 at 2:03
  • \$\begingroup\$ @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 ^^ \$\endgroup\$
    – Kaddath
    Dec 1 '21 at 12:37
5
\$\begingroup\$

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!

\$\endgroup\$
3
\$\begingroup\$

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 G 𝕩} F G F∘G, F○G
{𝕩 F (G 𝕩)} ⊢ F G F⟜G
{(F 𝕩) G 𝕩} F G ⊢ F⊸G
{𝕩 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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.