Author Topic: Optimization Help  (Read 5872 times)

0 Members and 1 Guest are viewing this topic.

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Optimization Help
« 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.

« Last Edit: February 01, 2009, 08:53:47 pm by trevmeister66 »
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: Optimization Help
« Reply #1 on: February 01, 2009, 06:43:24 pm »
What does this program accomplish, I have better luck sometimes just re-writing it.

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Re: Optimization Help
« Reply #2 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.
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: Optimization Help
« Reply #3 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...)

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Re: Optimization Help
« Reply #4 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.
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimization Help
« Reply #5 on: February 01, 2009, 09:16:48 pm »
nice, kinda like Illusiat 12 naming routine (also used in Illusiat 2004)

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Re: Optimization Help
« Reply #6 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.
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimization Help
« Reply #7 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.

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Re: Optimization Help
« Reply #8 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.
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: Optimization Help
« Reply #9 on: February 02, 2009, 12:31:51 am »
I made a small one, hope it works for what you want:



[Download 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

Offline trevmeister66

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1009
  • Rating: +14/-5
    • View Profile
Re: Optimization Help
« Reply #10 on: February 02, 2009, 01:01:03 am »
Thanks! That's a lot better.
Projects:    nameless RPG: 1.0%  |  Reverse Snake v1.5: 100%  |  Secret Project: 5%  |  DUNGEON: 70%

My MW2 Blog <-- Please visit :)

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimization Help
« Reply #11 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

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: Optimization Help
« Reply #12 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

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Optimization Help
« Reply #13 on: February 04, 2009, 01:14:05 am »
moved to calculator help and support