Tips for golfing in Fishing

6

I recently found out about the Fishing language, and it is now a favorite of mine. However, I'm finding it difficult to do anything cool with it, including code golf. Are there any tips for golfing with Fishing to use the least characters? And any string manipulation tricks would be cool, as I am finding that difficult in Fishing.

addison

Posted 2016-07-31T19:57:11.383

Reputation: 993

Answers

1

a and m work on strings too

Though it isn't explicitly stated in the spec, a (add) and m (multiply), at least in the official Ruby interpreter, also work on strings.

Say you had two cells with strings in them at the end of the tape, and wanted to concatenate and print them. You could do it with c:

c{{P

However, as long as you don't want to preserve the original value of your first cell, you could append the second string directly onto the first with a and avoid having to go to the end of the tape:

aP

Now let's say you want to print 20 spaces. The naive way to do it would be to simply hardcode them:

`                    `P

As long as the cell to the right is free, though, you can save 11 instructions by using m:

` `{`20`n}mP

Note, however, that due to the way Ruby works, you cannot do this with the order of the cells reversed (i.e. multiply a number by a string); that causes an error.

insert_name_here

Posted 2016-07-31T19:57:11.383

Reputation: 816

1

? doesn't need both an adjacent = and an adjacent !

This isn't explicitly stated in the spec either, but with the official interpreter, you do not need to surround a conditional (?) with both = and !; if one is not present and the condition matches it, the program will keep going in its original direction. An example:

v+CCCCCC?=CCCCCCCC
  I{`0`}! E`Zero`N
        [CCCCCCCCCCCC
         E`Not zero`N

This program prints takes a string and prints "Zero" or "Not zero", depending on whether it equals "0". You could shave off two bytes, however, by removing the = sign:

v+CCCCCC?CCCCCCCC
  I{`0`}!E`Zero`N
        [CCCCCCCCCCCC
         E`Not zero`N

insert_name_here

Posted 2016-07-31T19:57:11.383

Reputation: 816