Tips for golfing in S.I.L.O.S

5

What general tips do you have for golfing in S.I.L.O.S? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to S.I.L.O.S (e.g. "remove comments" is not an answer).

Please post one tip per answer.

S.I.L.O.S can be run here.

Rohan Jhunjhunwala

Posted 2016-09-25T12:53:52.500

Reputation: 2 569

Answers

2

Abuse the preprocessor

All SILOS programs can optionally have a macro statement on the second line

Consider the following program... One of my favorite SILOS submissions by betseg.

a=97
def q print z bottle v beer L Line g wall x IntNoLine h the c around
qL 99 zs of v on h g, 99 zs of v.
lbls
q Take one down and pass it c, 
a+1
qx a
qL  zs of v on h g.
qx a
q  zs of v on h g, 
qx a
qL  zs of v.
a-2
if a s
qL Take one down and pass it c, 1 z of v on h g.
qL 1 z of v on h g, 1 z of v.
q Go to h store and buy some more, 99 zs of v on h g.

Look at that savings Try it out!

Rohan Jhunjhunwala

Posted 2016-09-25T12:53:52.500

Reputation: 2 569

1

Never sometimes divide by 0.

Consider a challege where we should output the input if it is not 0 and output -1 otherwise. We could do the following.

S.I.L.O.S, 50 bytes

readIO
if i b
print -1
GOTO c
lblb
printInt i
lblc

Try it online!

However, that is far from optimal. The "superior" solution would be this.

S.I.L.O.S, 33 bytes

readIO
j=i
i/i
j=j+i-1
printInt j

Try it online!

SILOS will quietly ignore the division by 0, which results in a no-op.

Rohan Jhunjhunwala

Posted 2016-09-25T12:53:52.500

Reputation: 2 569

0

Never declare variables

There is no need to declare a variable. All variables are automatgically initialized to 0.
Hence, this-

a=0
a=97
printInt a

Is the same as this

a=97
printInt a

Rohan Jhunjhunwala

Posted 2016-09-25T12:53:52.500

Reputation: 2 569