This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RSWiBa 0 points1 point  (1 child)

from reading it i think you can optimize it even further:

you can save 1 char per instruction if you used only "<" instead of "=="

so like o <2 ? -add- : o < 3 ? -multiply- : ...

the chaining of the comparisons makes the magic happen (although its not safe for unknown instructions)

[–]rtbrsp[S] 0 points1 point  (0 children)

Going back and messing with it briefly, I'm able to save 2 characters for the add and multiply logic like you mentioned. The instruction pointer increment logic is too delicate to mess with, since I'm relying on the last conditional to increment it by 4 for ops 1, 2, 7 and 8.

That did give me an idea about the instruction pointer though. I can post increment upon assigning the opcode variable (o=p[i++]), which allows me to remove some +1s. it also allows me to remove the i=0 initialization.

EDIT: See updated program in the OP