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
(Try it Online!)
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 ƈṡ, ƛ€!
.
øD
is fully optimised and will always give you the shortest possible result. For example, compressing abcdef
will return ėġḣ²
.
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(⁼~∇Ċβ«
.
But what about numbers???
»
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.