Deadfish is one of the best known non Turing-complete programming languages. It has only one accumulator (which starts at 0) to store data, and only four commands:

i - Increment the accumulator
s - Square the accumulator
d - Decrement the accumulator
o - Output the accumulator


A Deadfish program may look like:

iiisdo


And that would print:

8


The challenge

Create a program that will input a number and output Deadfish code to display the number.(Or make a function that takes the number as a parameter and returns the code.) It must work for any integer from 0 to 255

Goal

Try to make your code make the shortest code possible to generate the given number. For example:

iiiiiiiiio


and

iiiso


each print 9, but the second is shorter.

Scoring

The number of characters in your source code +
The sum of the lengths of your output for all numbers from 1-255
-100 if the language you chose is Deadfish :)


Lowest score wins!

In the original challenge I only had the sum of 6 numbers(9,17,99,100 and 123). This was from me wanting to not make everyone test for every number, and I wanted the shortest code to be relevant. Then I realized that programmers are good at making scripts to test things like that, and I would rather have this be a contest for best algorithm with golfing as a tiebreaker.

Therefor I changed this, as suggested by Martin Büttner.

• How is doing this in Deadfish possible if it takes no input? – Calvin's Hobbies Oct 21 '14 at 20:37
• @Calvin'sHobbies I don't think anyones getting that -100:) – MegaTom Oct 21 '14 at 20:41
• Related – Peter Taylor Oct 21 '14 at 22:43
• Does deadfish handle integers larger than 255? E.g. can we calculate 256 and subtract one? How is overflow handled? Is 16^2 = 0 or 16^2 = 256 or 16^2 = error? – soktinpk Oct 21 '14 at 22:55
• @soktinpk If you hit -1 OR 256, then it gets reset to 0. But if you hit a number bigger than 256 by squaring then it's unchanged, e.g. 17^2 = 289. (see the esolang page) – Sp3000 Oct 21 '14 at 23:13

Perl, 132 131 bytes + 2036 bytes = 2167

Includes +2 for -lp

Run with the target number on STDIN, e.g.

perl -lp deadfish.pl <<< 160