Tips for golfing Yabasic

1

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.

Helpful Resources

Yabasic Official Website

Yabasic Manual

Yabasic Wikipedia Page

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.

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709

1Yet Another 'Yet Another' Language – Stan Strum – 2018-03-03T19:34:41.867

@StanStrum Yeah, there are quite a few members of the 'Yet Another' paradigm

– Taylor Scott – 2018-03-04T17:53:08.760

Answers

1

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!

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709

1You might want to specify that this only works for individual digits. – HyperNeutrino – 2018-03-02T13:21:47.900

@HyperNeutrino I've modified the response to include that note - thanks for the Input :) – Taylor Scott – 2018-03-02T18:21:18.313

0

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.

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709

0

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.

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709

0

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

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709

0

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!

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709

0

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)

Taylor Scott

Posted 2018-02-15T04:32:38.440

Reputation: 6 709