Tips for golfing in uBasic

2

UBASIC is a freeware interpreter written by Yuji Kida at Rikkyo University in Japan, specialized for mathematical computing. It is considered to be a "ready-to-run" language that and is capable of running on DOS and Windows.

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

Some helpful links

uBasic Wikipedia Page

Try it Online

Taylor Scott

Posted 2018-01-24T18:03:00.597

Reputation: 6 709

Answers

1

Use ? in place of Print

Instead of using the Print command, ? may be used, as is the case in many BASIC languages - this means that the most simplest uBASIC Hello, World! program is as follows

0?"Hello, World!"

Rather than

10 Print "Hello, World!"

Try it Online!

Taylor Scott

Posted 2018-01-24T18:03:00.597

Reputation: 6 709

1

Avoid Whitespace in For and Like statements

Whitespace between For and a variable name is not necessary in uBASIC meaning that a For loop may be condensed from

0 For t = 1 To 2
1 ?t
2 Next t

to

0Fort=1To2
1?t
1Nextt

Try it Online!

Taylor Scott

Posted 2018-01-24T18:03:00.597

Reputation: 6 709

1

Execute multiple commands on a single line with :

uBasic allows for the execution of many commands on a single line with the use of : over a new line and new line number.

This means that this (50 Bytes)

0Fori=0To10
1Forj=1To9Step3
2?i*10+j
3Nextj
4Nexti

May be condensed to this (46 Bytes)

0Fori=0To10:Forj=1To9Step3:?i*10+j:Nextj:Nexti

Try it Online!

Taylor Scott

Posted 2018-01-24T18:03:00.597

Reputation: 6 709

0

Use ; to Print Without a Newline

Much like is the case in VBA and other BASIC languages, you may add a ; to the end of a print statement to keep from printing a newline character and continue printing on that line.

Example:

0For i=1 To 10
1?i;
2Next i

Outputs

12345678910

Try it Online!

Similarly, , may be appended to the end of a print statement to prevent to pad the output right to a width of eight characters (note however, the output number or string must be of a length less than or equal to 6 characters)

Example

0?1,"|"

Outputs

1       |

Try it Online!

Taylor Scott

Posted 2018-01-24T18:03:00.597

Reputation: 6 709