# Tips for golfing Yabasic

Yabasic, or Yet Another Basic is a dialect of created by Marc-Oliver Ihm that may be run on Windows, Unix and PAL versions of the Sony PlayStation 2. Development for this language is ongoing.

Yabasic Official Website

Yabasic Manual

Yabasic GitHub

Yabasic PS2 Documentation

Some Yabasic Programs

Try it Online

What general tips do you have for golfing in Yabasic? Any ideas that can be applied to code golf problems in general that are at least somewhat specific to Yabasic. Please post one tip per answer.

• Yet Another 'Yet Another' Language Mar 3, 2018 at 19:34
• @StanStrum Yeah, there are quite a few members of the 'Yet Another' paradigm Mar 4, 2018 at 17:53

# Use Chr$(...) to Print numbers By default, all numbers printed using Yabasic print with a space following them, and to remove this space while printing characters individually, one may use the formula below. It is important to note that this only works for printing digits 0 - 9, meaning that this works best for iterating across numbers digit by digit. ... ?Left$(Str$(n),1); ...  Try it online! However, if the context allows, this can be golfed down to this formula. ... ?Chr$(n+48);
...


Try it online!

• You might want to specify that this only works for individual digits. Mar 2, 2018 at 13:21
• @HyperNeutrino I've modified the response to include that note - thanks for the Input :) Mar 2, 2018 at 18:21

# Use ?n,"",m to print two numbers without spaces

Given two numeric variables n and m, they may be printed directly beside one another (as if concatenated) by formatting the print statement as

?n,"",m


which is significantly shorter than direct concatenation, which would require converting the numeric to a string with something of the form of

?Str$(n)+Str$(m)


# Use ? Instead Of Print

Much like many dialects of BASIC, such as VBA and uBasic, Yabasic allows for the use of the ? Character for printing to the console in place of the Print  keyword.

In addition you may use ; to print without any trailing newline or other characters.

Each use of this saves 5 bytes.

# Use Fi Instead of EndIf

Much like Bash and other languages, Yabasic has the keyword Fi that allows for the termination of If(...)Then blocks.

Each use of this saves 3 bytes.

# Use abbreviated Print At(x,y)"..."

Because has no string repetition or replacement function built, it is often more efficient to convert an answer to graphics mode and use the Print At() command than to deal with using for loops to determine spacing.

This may be abbreviated as

?@(x,y)"your text"


This may also be combined with the color modifier of the print statement to make statements such as

?Color("Blu")@(x,y)"your text"


it is however noted that use of this command requires that the clear screen command has been called at least one in the solution.

An example of a yabasic solution using the ?@() may be seen here

# Use n/0, inf and nan

While not included in the Yabasic Manual (at present), yabasic includes some interesting edge cases for numbers, namely, allowing for division by zero, infinite values and nans.

### Division by Zero

n/0


Regardless of the input value the output of the above snippet shall be exactly equivalent to 2^1024. Interestingly, this includes negative inputs, infinite inputs and nan inputs.

### Infinity

9^999


If you try to use too large a value, then Yabasic will convert it to inf. As far as I am aware, the above is the shortest snippet that may be used to access inf, as inf may not be called directly. This behaves as expected.

### Not a Number

n=9^999
?n-n


If you try to take an infinite number from an infinite number, Yabasic will return nan (not a number).

Try it online!