Page 1 of 12

[TI BASIC] Optimizing

Posted: Thu 24 Feb, 2005 1:09 am
by kalan_vod
well is there a way to optimize this?

getkey->O
if O=26
then
if x>16
-8->x
x+8->x
if x=24
delvar x
end
if O=24
then
if x<=16 or x>+40
16->x
x+8->x
end



like is there a boolean way or am i blind? :?

Re: [Ti Basic] optimizing

Posted: Thu 24 Feb, 2005 3:30 am
by Guest
kalan_vod wrote:well is there a way to optimize this?

getkey->O
if O=26
then
if x>16
-8->x
x+8->x
if x=24
delvar x
end
if O=24
then
if x<=16 or x>+40
16->x
x+8->x
end



like is there a boolean way or am i blind? :?

Code: Select all

getKey
If Ans=26
Then
If X>16
-8->X
X+8->X
X-(X=24)X->X
End
If Ans=24
Then
If X<=16 or X>+40
16->X
X+8->X
End
Shrinked it just a pickle...

Posted: Thu 24 Feb, 2005 3:40 am
by kalan_vod
thanks but this wouldn't help much and also i use the getkey ans in the entire program, i just was trying to make it faster :D

Posted: Thu 24 Feb, 2005 5:01 am
by Guest
Replace

Code: Select all

if x=24
delvar x 
with

Code: Select all

X-(X=24)X->X 
meh

Posted: Thu 24 Feb, 2005 10:07 am
by Guest
I believe this code can replace the "if O=26:then:end" code:

Code: Select all

X+(O=26)(8-(8+x)(x>=16)->X

Posted: Thu 24 Feb, 2005 9:12 pm
by kalan_vod
gj man i appreciate it :D it didnt relly make it faster but its 2 bytes smaller :)

Posted: Fri 25 Feb, 2005 2:24 am
by Virtuoso
You could try to describe what you want
There could be a better way to do it that you dont see

~Virtuoso

Posted: Sat 26 Feb, 2005 7:16 pm
by merthsoft
I, too, am in need of some optimization help, and this has become the official BASIC optimization thread, so here's my code:

Code: Select all

If K=24 or K=31:3->D
If K=25 or K=22:1->D
If K=26 or K=33:2->D
If K=34 or K=32:0->D
I am looking more for speed than size, any help would be appreciated, thanks.[/code]

Posted: Sat 26 Feb, 2005 10:12 pm
by Guest
This code should do what you want. It is optimized for speed and size. The one caution about it is that it sets the D variable to zero if none of the Boolean conditionals are true. You don't specify if you need the D variable for anything else, so I just assumed you didn't.

Code: Select all

3(K=24 or K=31)+2(K=26 or K=33)+(K=25 or K=22->D

Posted: Sun 27 Feb, 2005 4:49 pm
by merthsoft
Yeah, I probaly should have specified that I do...

Posted: Sun 27 Feb, 2005 5:48 pm
by Shadow Phoenix
Do
:D->L1(1)
:3(K=24 or K=31)+2(K=26 or K=33)+(K=25 or K=22->D
:if D = 0
:L1->D

Posted: Sun 27 Feb, 2005 6:07 pm
by CoBB
This isn't correct, because 0 is also a valid value.

Posted: Sun 27 Feb, 2005 8:09 pm
by leofox
If D=0

can be optimized to

If not(D

Posted: Mon 28 Feb, 2005 3:07 am
by Guest
Is there anyway to optimize this?

Code: Select all

1->B
16->Y
For(F,1,99
If X=A and Y=B
Goto 3
Output(X,Y,6
Output(A,B,9
randInt(1,5-C
If C=/5
Output(X,Y,"_
getKey->K
If K=/0
Output(A,B,"_
X-(C=1 and X=/1)+(X=/8 and C=2)->X
Y-(C=3 and Y=/1)+(Y=/8 and C=4)->Y
B-(K=24 and B=/1)+(B=/16 and K=26)->B
A-(K=25 and A=/1)+(A=/8 and K=34)->A
End
Lbl 3


_ means space
=/ means not equal to
Attempting to make the smallest Cops and Robbers game =\

Posted: Mon 28 Feb, 2005 3:26 am
by Guest

Code: Select all

If K=/0
to
If K
-------
X-(C=1 and X=/1)+(X=/8 and C=2)->X 
to
X-(C=1 and X=/1)+(X=/8 and C=2->X 
There might be more...