# Tips for Golfing in Vyxal

Vyxal is a golfing language that has 500+ different commands (achieved through overloads), and is a known beater of Jelly, 05AB1E and most golfing languages.

Henceforth, it seems like a good idea to share some of the tips and tricks of the industry used to get terse programs in Vyxal.

One tip per answer, and no stupid tips like "oh remove comments and whitespace".

• Can we actually enforce the "one tip per answer" please, unlike every other tips question ever? Even if answers are good, please downvote them if they contain more than one tip – pxeger Apr 20 at 6:55
• @pxeger I think that seems reasonable – lyxal Apr 20 at 6:55

# Brackets/Structures autocomplete

Totally not stolen from Tips for golfing in keg because Vyxal totally isn't supposed to be keg but 69 times better

If you have a structure (e.g. if/for/while/function/lambda) at the end of your program, and EOF follows, you can leave the closing bracket/semicolon off. Note that this only applies if you are submitting a full program.

For example:

9(0,)


Can be shortened to:

9(0,


And:

{:1=[1,]}


Can be shortened to:

{:1=[1,


# Remember that mapping/filtering/reducing all cast numbers to ranges

Okay so say you want to apply something over the range [1, n] using Map, Filter or Reduce (or ḭnverse reduce/foldr). Your first instinct might be to do this:

ɾλ....;M # or whatever command you're using


This is unnecessary, as the functional programming commands all cast numbers to range before doing their job, so:

λ....;M


is equivalent.

"But what if my range isn't [1, n], but instead [0, n] or [1, n) for example? Won't I need the corresponding range command?"

Well yes, but actually no if you use flags:

M Make implicit range generation start at 0 instead of 1

m Make implicit range generation end at n-1 instead of n

(source: flag help generated using the -h flag).

# Use of filter lambda

Filter lambda (') can filter out the items which are not truthy from the stack, so you don't need a lambda map and close it and then find out the Truthy indices.

This is a code using the lambda map

ƛǐG5>;T›


But if you use filter lambda, it can be shortened to

'ǐG5>


the last 3 commands are no longer needed!

• This also applies for map lambdas too – lyxal Apr 20 at 7:46

# Use the multi-element lambdas if your lambda body is 1-3 bytes

Say you have the following:

λǐṅ;Ẋ


You can turn this into

‡ǐṅẊ


Because ‡ combines the next two elements (built-ins) into a single lambda. ⁽ is for 1 element lambdas (good for when you want to reduce/filter/map a built-in without using v) and ≬ is for 3 element lambdas.

# Use \ for single byte strings and ‛ for two byte strings

Sometimes you'll need a string of either one or two characters. You could do the following:

A
AB


But that has an extra backtick at the end. Instead, you can do this:

\A
‛AB


## Important

\ pushes the next character as a string no matter what it is. ‛ will treat it as if the next two characters were wrapped in backticks (meaning that it will dictionary uncompress a single string compression code).

# Compress your strings and numbers

Nobody likes long strings. And nobody likes long numbers either. Luckily there's two ways of compressing strings and one way to compress numbers.

## Dictionary Compression

Fun fact: Vyxal has access to a roughly 20k word "dictionary" (read: a list of words) which can be used to shorten strings with a) common English words or b) common 3 letter combinations.

To access the words in this dictionary, you need to get the String Compression Code (SCC) of the word and place it inside a normal string (the backtick ones). String Compression Code is simply a way of saying "the base 10 index of the word within the dictionary list converted to a bijective base-1611".

You can get the SCC of a word by using øD. For example:

HelloøD


Tells you the SCC for Hello is ƈṡ. However, øD will also return the dictionary compression of a given string:

Hello, World!øD


Is turned into ƈṡ, ƛ€!.

Note that the result of øD may not always be optimal:

abcdeføD


Will return abcdef, even though ėġḣ²2 is shorter and uses dictionary compression.

## Base-255 Compression

But what if your string is a bunch of random letters that aren't in the dictionary at all? øD becomes useless for obvious reasons. In this case, you would use « delimited strings.

These strings take everything inside of them, converts it from a bijective base-255 (the vyxal codepage minus «) to base 10. It then converts that result to a bijective base-27 (the lower case alphabet plus space). Important: only stings containing lower case letters and spaces can be Base255 compressed3.

To get the Base255 compression of a string, you can use øc:

ahroebeodbslnwksozlzbeoxbeodbsonwkdbdiøc


Tells you that the compression is «∧pŀQb⟨ż₄∑ṄḞḊjẎɾ71(⁼~∇Ċβ«.

» strings have got you covered. øC will take an integer and return it converted to a bijective base-255 (the vyxal code page minus »:

69694204206969øC


Gives you »A⟩¾Ǐø7»

1: The bijective base 161 is simply the vyxal code page minus all printable ascii. This is so that SCCs can be embedded inside strings without creating a new string type.

2: Yeah, SCCs don't need to be surrounded by spaces - they can be inside ascii (a÷×b) or even next to each other (£÷¬¶). This is very intentional.

3: I originally allowed for upper and lower case inside base 255 strings, but found that strings are usually shorter when only allowing lower case.

# Custom base decompression

When you're compressing a large amount of data with a limited charset, as in here, you can use a base-255 integer (»...») and the custom base decompression function τ.

For example, say you want to compress this ascii-art:

  /
/ \
\   \
\ / \
/   /
/ \ /
\   \
\ / \
/   /
/ \ /
\   \
\ / \
/   /
/ \ /
\   \
\ /
/


You can just map 0 to \, 1 to /, and 2 to   to get 576780841113635223227691120919222477677740273185690732841 in base-3, which compresses to »ɾĠ^;√⟑•ȮṙDǓ…⟩P½≠1⅛²ė"÷₆Ŀ».

Then, you can take out your compression guide \/ , and append τ to turn it into base-3 with those as values.

Finally, you can split into 17 pieces (for 17 lines) and output joined by newlines - Try it Online!

# Use the register instead of a variable

Sometimes, you're using a variable over and over again, and it's using so many bytes, right? Well, if you only have 1 variable, you can use the register instead, and save a byte every time you use it!

For example, say you want to do x * 2 and x ^ x. You could do:

3→x ←xd, ←x←xe,


This saves 3 to x, then retrieves it and doubles it, then retrieves twice, and exponentiates. However, x is being used 4 times, so that's 8 bytes in variable references alone! Using the register will shorten this code a lot:

3£ ¥d, ¥¥e,


Instead of saving to and retrieving from a variable, we're using the register, which can be accessed using only 1 byte. Anytime you're using variables, you can replace one of the variables with the register to save some bytes!