Re: TIB: challenge
[Prev][Next][Index][Thread]
Re: TIB: challenge
Well, you could shrink it a bit by combining the
statements dealing with the same variable (meaning just one store [->] for
the X var etc), since the less store [->] operations the calc does, the
faster it goes.
Try this for the X and Y operations:
:X+(A=26)(X<16)-(A=24)(X>1) /->/ X
:Y+(A=34)(Y<8)-(A=25)(Y>1) /->/
Y
This code uses no IF statements and reduces the
number of stores [->] to just 2, while retaining full functionality. It
relies on Boolean logic to determine whether (A=26) AND (X<16), returning
a 1 or 0 if each tests true or false, respectively. You can
manipulate these values to either add 1 or subtract 1 from the value of X (or Y)
to get the desired effect.
(Can you tell I'm a big fan of Boolean
logic?)
Plus, if you build a loop around the
GetKey within the main loop, the code will be more responsive when the user
hits a key. (because otherwise, if you hit a key while the calc is
handling the IFs, there's no response.)
here's my 83 version, I have refined a lot, I think this is THE
smallest
you can get for 83> Tell me if I'm
wrong.
:8->X:4->Y
:While
A<>45
:getKey->A
:Output(Y,X," "
:If A=24 and
X<>1
:X-1->X
:If A=25 and Y<>1
:Y-1->Y
:If A=26
and X<>16
:X+1->X
:if A=34 and
Y<>8
:Y+1->Y
:Output(Y,X,"O"
:End
The Character is
"O" and if you press [CLEAR] it stops.
Follow-Ups:
References: