Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: trevmeister66 on February 01, 2009, 05:03:11 pm

Title: Optimization Help
Post by: trevmeister66 on February 01, 2009, 05:03:11 pm
Well it's been a long time since I've programmed on the calc, so I'm a little rusty. I was just wondering if someone could help me optimize this code for speed:
Code: [Select]
ClrHome
"________->Str2   //8 Spaces in Str2
"_ABCDEFGHIJKLMNOPQRSTUVWXYZ->Str1
Ouput(1,1,"Whats your name?
Output(3,1,"NAME: "+Str2
7->X
8->dim(L1
For(Y,1,8
1->L1(Y
End
Repeat K=105
Output(2,X,"^   //up arrow
Output(4,X,"v   //down arrow
getKey->K
//Moves arrows left or right
If K=24 or K=26
Then
Output(2,X,"_    //_ = Blank Space
Output(4,X,"_    //_ = Blank Space
X+(K=26)-(K=24
Ans+8(Ans=6)-8(Ans=15->X
End
If K=25 or K=34
Then
L1(X-6
Ans+(K=25)-(K=34
Ans+27(Ans=0)-27(Ans=28->Z
If X=7
Then
sub(Str1,Z,1)+sub(Str2,2,7
End
If X>7 and X<14
Then
sub(Str2,1,X-7)+sub(Str1,Z,1)+sub(Str2,X-5,14-X
End
If X=14
Then
sub(Str2,1,7)+sub(Str1,Z,1
End
Ans->Str2
Z->L1(X-6
Output(3,7,Str2
End
End
//Delete all variables

If you need more information about what this program does, just ask.

Title: Re: Optimization Help
Post by: kalan_vod on February 01, 2009, 06:43:24 pm
What does this program accomplish, I have better luck sometimes just re-writing it.
Title: Re: Optimization Help
Post by: trevmeister66 on February 01, 2009, 08:37:27 pm
It lets the person create a 8-max letter name. They can move left or right and change the letter at that position. Every time you change a letter (by pressing up or down) it recreates the String (Str2) and displays it again. I know there's easier and faster ways to do it, but I also want it to look good instead of just entering it like normal.
Title: Re: Optimization Help
Post by: {AP} on February 01, 2009, 08:48:29 pm
Minor problem.
Look below... it shows it. (only hitting the arrows... the error happens on pressing up/down on the 2nd space)
This is just a direct copy of your code above.

I was testing it before I play with the optimizing... and that happened.
Can't find the issue... (maybe just too tired...)
Title: Re: Optimization Help
Post by: trevmeister66 on February 01, 2009, 08:52:45 pm
Heh I know why. In the code that say
Code: [Select]
If X>8 and X<14 should be
Code: [Select]
If X>7 and X<14
Heh I have it right in my program.
Title: Re: Optimization Help
Post by: DJ Omnimaga on February 01, 2009, 09:16:48 pm
nice, kinda like Illusiat 12 naming routine (also used in Illusiat 2004)
Title: Re: Optimization Help
Post by: trevmeister66 on February 01, 2009, 09:18:19 pm
nice, kinda like Illusiat 12 naming routine (also used in Illusiat 2004)
O snap. Do you think you have the code for that lying around anywhere? I'd like to take a look at it and see what differences we have and see what I can improve on.
Title: Re: Optimization Help
Post by: DJ Omnimaga on February 01, 2009, 09:23:03 pm
Well, I doubt it is a good example. Back in the days (2002-2003) I was still using lbls/gotos inside loops, and some parhentesis were closed and " not omitted at the end of strings, just to give you an idea. If I have time to dig up the code I will post it though, but it's horrible. I would most likely do signifiantly better today.
Title: Re: Optimization Help
Post by: trevmeister66 on February 01, 2009, 09:25:32 pm
Heh yeah I understand, but it never hurts to look at it even just to see how it works (even if it is unoptimized). but if you don't have it right now it's all good.
Title: Re: Optimization Help
Post by: kalan_vod on February 02, 2009, 12:31:51 am
I made a small one, hope it works for what you want:

(http://group.revsoft.org/_theta_theta_Z.gif)

[Download 8xp] (http://group.revsoft.org/_theta__theta_Z.8xp)

Quote from: BASIC Code
:ClrHome:1→A:"ABCDEFGHIJKLMNOPQRSTUVWXYZ →Str0:"-→Str1:8→dim(L1:Fill 1,L1
:Output(1,1,"WHATS YOUR NAME?
:Output(4,1,"NAME:
:Repeat θ=21
:L[size=0]1[/size](A→B
:Repeat θ=21 or θ=26 or θ=24
:A+6
:Output(3,Ans,"
:Output(5,Ans,"
:Output(4,Ans,sub(Str0,B,1
:getKey→θ
:B+(Ans=34)-(Ans=25
:Ans-27((Ans=28)-not(Ans→B
:End
:sub(Str0,Ans,1
:If θ=24:Then:"
:Output(4,A+6,Ans:End
:sub(Str1,1,A)+Ans→Str1
:inString(Str0,sub(Ans,A+1,1→L[size=0]1[/size](A
:A+6
:Output(3,Ans,"
:Output(5,Ans,"
:A+(θ=26 and A≠8)-(θ=24 and A≠1→A
:End
:sub(Str1,2,Ans→Str1
Title: Re: Optimization Help
Post by: trevmeister66 on February 02, 2009, 01:01:03 am
Thanks! That's a lot better.
Title: Re: Optimization Help
Post by: DJ Omnimaga on February 02, 2009, 01:57:13 am
I assume these are the characters added in OS 1.15 or higher? This looks nice actually
Title: Re: Optimization Help
Post by: kalan_vod on February 02, 2009, 02:13:44 am
I believe so kevin, you can get them in tifreaks font pack on ticalc. I actually now see a few optimizations in my own code..ew
Title: Re: Optimization Help
Post by: DJ Omnimaga on February 04, 2009, 01:14:05 am
moved to calculator help and support