Tips for Golfing in Vitsy

7

While there are only a few users of the Vitsy programming language right now, I wish to create a place for tips for golfing in Vitsy.

What general tips do you have for golfing in Vitsy? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Vitsy (e.g. "remove NOPs" is not an answer). Please post one tip per answer.

For reference, the online interpreter is here, the esolang page is here, and you can receive answer-per-answer help here.

Addison Crump

Posted 2016-02-09T21:37:46.283

Reputation: 10 763

Answers

2

Do not doubt the power of m

Background: Fm calls the a specified line index in the current Vitsy class. (F is the line index you seek).

The m command (method) has saved me literally hundreds of bytes in the past. Any algorithm that uses repeated steps, or a common character sequence (such as D1M- (floor algorithm)).

This is extremely helpful in repetitive kolmogorov complexity challenges.

Instead of:

WD1M-(something else here)WD1M-(something different)WD1M-l\[NaO]

Use:

1m(something else here)1m(something different)1ml\[NaO]
WD1M-

(floor(prompt))

Also, you can return from method statements with ;, allowing for looping until condition(s) (over the general [ ] syntax, which isn't as powerful):

1mN
<;)

(loops through code until finding non-zero, popping it from the stack and returning to first line)

Addison Crump

Posted 2016-02-09T21:37:46.283

Reputation: 10 763

Since many people here don't know vitsy, perhaps briefly explain what m does? – Cyoce – 2016-02-10T22:49:16.470

@Cyoce Yes, sorry. c: Corrected. – Addison Crump – 2016-02-10T23:01:59.470

2

Remember that \[] always runs at least once

Even if the top item of the stack is zero or less, \[] always runs. Think of it more as a do{}for(); loop. This has caught me off more than once, but it is important.

Addison Crump

Posted 2016-02-09T21:37:46.283

Reputation: 10 763

1

Filling Zeroes on an Empty Stack

Normally, to fill up the stack with a number, you would do something like this:

a\a

This fills up the stack with 10 10s, by pushing 10 10 times. However, if you wanted to push 10 0s, you'd do this:

a\0

After a recent update, however, the stack will attempt to fix for IndexOutOfBoundsExceptions by pushing 0s to a possibly empty stack, meaning that, if on an empty stack, you can do:

a%

Since % calls multistack, it tries to access every member between the top item (which is nothing after it pops 10) and the index you specify. Therefore, you get a stack with 10 0s when this is called. You can use this trick up to approximately 11380, although, annoyingly, it doesn't always go to a specific point...

UNKNOWN:Desktop addisonc17$ vitsy --code "2d^2b^+2a^+26^+25^+24^+5+%lNaO"
java.lang.StackOverflowError thrown in [command line] at command #0,25: %
UNKNOWN:Desktop addisonc17$ vitsy --code "2d^2b^+2a^+26^+25^+24^+5+%lNaO"
11381

Past that, you'll have to use the normal duplication method.

Addison Crump

Posted 2016-02-09T21:37:46.283

Reputation: 10 763