3
\$\begingroup\$

Thunno 2 is a stack-based golfing language with around 400 commands (achieved through overloads) created by me, The Thonnu.

It seems like a good idea to share some tips for golfing in Thunno 2.

Please, one tip per answer, and no tips like “remove comments and whitespace”.


Links:

\$\endgroup\$
0

6 Answers 6

5
\$\begingroup\$

Variables

Thunno 2 has many variables. Here they are.

x and y

x and y are initialised to 1 and 2. You can get them by using x and y, and set them by using X and Y. As well as that, you can set them without popping by using and , and apply a command to them by using and .

n and

These are context variables, so you cannot set them. n takes the value of the current loop variable, and takes the value of the iteration index (0-indexed). You can get them by using n and .

¡ and !

You can name variables using ¡ and !. All variables in Thunno 2 have a one-character long name. You can get a named variable by using ¡ and then the name. You can set a named variable by using ! and then the name.

Ȥ and ȥ

This is the global array. It is initialised to an empty list at the start of the program. You can get it by using Ȥ and add to it by using ȥ. Currently, there is no command to remove an item from the global array, but it may be added in the future.

\$\endgroup\$
4
\$\begingroup\$

Compress your numbers, strings, and lists

Thunno 2, like many other golfing languages, has utilities to compress numbers, strings, and lists. Here they are.

Base 255 compression

You can compress all three data types in base 255.

Numbers

This is the simplest one. You can just convert your number to base 255 using the Thunno 2 Codepage. This program can compress a number for you. For example, 1234567890 can be compressed into »Jt€Ṇ».

Compressed numbers are delimited by ». However, you can also compress smaller numbers with «. If your number is less than 65025, you can use « followed by two characters from the codepage, which saves you one byte from the ending delimiter. For example, 54321 can be compressed into «ḍ©.

Strings

You can compress a string which consists only of letters and spaces in base 255. This program can compress a string for you. For example, "n ne e se s sw w nw" can be compressed into “£ḂA⁷<ọŒ⁼Ẓ2Ẏ®“.

Lowercase compressed strings are delimited by . Title case compressed strings are delimited by .

Lists

You can also compress numeric lists in base 255. This program can compress a numeric list for you. For example, [43,44,45,46,60,62,91,93] can be compressed into ¿€ỵæ-j2oẹ&⁵ẏ¿.

Compressed numeric lists are delimited by ¿. You can compress the following characters only: 0123456789-.,. You can leave out the brackets when compressing.

Dictionary compression

Thunno 2 has a dictionary consisting of around 32000 words. Each of these words can be compressed in 2 characters. This program can optimally dictionary compress a string for you. (Note: the program will not give you the delimiters). For example, "Hello, World!" can be compressed into ’Ƙ¥, «ʋ!’.

Lowercase dictionary compressed strings are delimited by . Title case dictionary compressed strings are delimited by . Any alphanumeric characters will not be compressed, so ’Ƙ¥, «ʋs!’ is "Hello, Worlds!”. The same goes for the characters .,!?:\"'% ().

\$\endgroup\$
4
\$\begingroup\$

Use the flags

Thunno 2 has some very useful flags that can often shave 2 or more bytes off of your answer. Here's the full list, but I'll show off a couple here that are particularly useful.

J, j, N, n, ,

These flags are used to join a list to a string by a specific character, and can be very useful in many challenges. Each uppercase letter joins the top of the stack, while the lowercase equivalent joins the entire stack.

  • J and j join by nothing
  • N and n join by newlines
  • and join by spaces

B

The B flag converts any input strings to integer arrays representing the codepoint of each character, and any integer array output back to a string. This is very useful for -based challenges, where you have to transform some string or maybe just need to output some characters with a high codepoint.

G, M, S, s

These flags are pretty standard in golfing languages these days, but that doesn't mean they aren't useful. G returns the maximum of the top of the stack, M the minimum, and S the sum. There is also s for the sum of the entire stack.

v, e

These flags aren't necessarily useful for golfing, but they can come in very handy. As of writing this, they are deemed "experimental." e automatically outputs an explanation of your code, with the definition of each command commented to the side. v enables verbose mode, which lets you use long token names for builtins while developing your answer, which you can then switch to regular commands when you've finished. I encourage you to try them out, though you may or may not find them useful.

There are other useful flags, but these are just a few that seem particularly handy to me.

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

Use shortcut endings

(This only works in Thunno 2.2.0+. Attempt This Online is on 2.1.9, so it will not work there.)

So let's say we need a discard filter (i.e. remove items for which the filter code is true). Simple, right? Just use a filter and a not:

æ ... ¬;

But what if I told you we can go one byte better? You see, there is actually a shortcut for ¬;, and that's }. So a discard filter will be:

æ ... }

Similarly, : is a shortcut for =;.

Note: } will not work at the end of a for loop, and : will not work in an if statement, but they work everywhere else (map/filter/sort by/group by/while/etc.)

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

Remember that mapping/filtering/etc. casts numbers to ranges

If your code looks like this:

Rı ... ;

The R is unnecessary as numbers are implicitly cast to ranges when mapping/filtering/etc.

So, you can just use:

ı ... ;

Note: implicit range generation is always [1..n] (R). Anything else will need something before the map/filter/etc.

  • If you want [0..n), use L
  • If you want [0..n], use Ė
  • If you want [1..n), use ė
\$\endgroup\$
2
  • \$\begingroup\$ This one seems really handy--is this documented anywhere? \$\endgroup\$
    – noodle man
    May 15, 2023 at 10:16
  • 1
    \$\begingroup\$ @Jacob I have just added it to the tutorial \$\endgroup\$
    – The Thonnu
    May 15, 2023 at 17:13
1
\$\begingroup\$

Use one, two, and three character strings

In Thunno 2 strings start and end with ". But there are also other strings that don't need an ending delimiter:

  • ' is a one-character string. It pushes the next character to the stack as a string.
  • ` is a two-character string. It pushes the next two characters to the stack as a string.
  • ʋ is a three-character string. It pushes the next three characters to the stack as a string.

But be careful. ` and ʋ might try to decompress a dictionary-compressed string if you give them the wrong characters:

  • ` will look at the next two characters. If both of them are in the dictionary codepage (i.e. neither of them are in the uncompressable characters string below), it will decompress them as a dictionary-compressed word. Otherwise, it will default to normal behaviour.
  • ʋ will look at the next four characters. If all four of them are in the dictionary codepage (i.e. none of them are in the uncompressable characters string below), it will decompress them as two dictionary-compressed words. Otherwise, it will default to normal behaviour.

These are the uncompressable characters in Thunno 2: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?:\"'%() ‘’

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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