Don't have an account? Register now to chat, post, use our tools, and much more.
Online Users
There are 132 users online: 11 members, 94 guests and 27 bots.
Members: cheapie, DHerls, HOMER-16, lakshminarayan rajaram, piano4lifez, rcfreak0, Runer112, Tari.
Bots: Spinn3r (1), MSN/Bing (2), Magpie Crawler (3), VoilaBot (2), Googlebot (19).
SAX
Author Message
zeldaking

Power User

Joined: 31 Jul 2011
Posts: 470
Location: Utah

 Posted: 09 May 2012 10:41:09 pm    Post subject: Ti-Basic Optimization Recently I have been teaching a kid at school Ti-Basic. I am now teaching him about optimizing. I made a simple 'game' in 96 bytes but wondering if I could make it smaller. The 'game' moves a '*' around without letting it leave the homescreen boundaries. Yeah I know very simple. Here is what I have: Code: ``` :1->A:1->B :Repeat K=45 :getkey->K :ClrHome :Output(B,A,"* :A+(K=26 and A!=16)-(K=24 and A!=1)->A :B+(K=34 and B!=8)-(K=25 and B!=1)->B :End //!= not equals to ``` Thanks
blue_bear_94

Member

Joined: 20 Apr 2012
Posts: 162

 Posted: 09 May 2012 10:51:02 pm    Post subject: Code: ``` :1->A:1->B :Repeat K=45 :getkey->K :ClrHome :Output(B,A,"* :A+(Ans=26 and A!=16)-(Ans=24 and A!=1->A :B+(K=34 and B!=8)-(K=25 and B!=1->B :End //!= not equals to ```_________________Do NOT click any links!
TheStorm

NOU!

Joined: 26 Mar 2007
Posts: 2375

 Posted: 09 May 2012 10:51:38 pm    Post subject: Re: Ti-Basic Optimization Code: ``` :1->A:1->B :Repeat K=45 :ClrHome :Output(B,A,"* :getkey->K :A+(Ans=26 and A!=16)-(Ans=24 and A!=1->A :B+(K=34 and B!=8)-(K=25 and B!=1->B :End ``` Saved two bytes and made a slight speed optimization. I know there is more to be saved but that is what I saw with a quick glance. Edit: Blue_bear beat me too it, then again I took the time to say what I did._________________ "Always code as if the person who will maintain your code is a maniac serial killer that knows where you live" -Unknown "If you've done something right no one will know that you've done anything at all" -Futurama "Have a nice day, or not, the choice is yours." Tom Steiner or create a Borg collective and call it The 83+ Lower your slide cases and prepare to be silent linked. Memory clears are futile.
zeldaking

Power User

Joined: 31 Jul 2011
Posts: 470
Location: Utah

 Posted: 09 May 2012 10:54:02 pm    Post subject: Oops sorry, I accidentally wrote those closing parentheses... just going off of memory. looking at my code I didn't have those :p
Compynerd255

Power User

Joined: 08 Apr 2011
Posts: 397

 Posted: 10 May 2012 09:15:29 am    Post subject: In floating point operations, does "While K-45" save speed over "Repeat K=45"? I know that it saves time and speed in Axe._________________Visit Betafreak Games: http://www.betafreak.com Help Me Pay for College: - Sign up for Fastweb through my referal link!
Aes_Sedia5

Minor Calculator Deity

Joined: 01 Sep 2011
Posts: 1002
Location: Where Nightmares end and Dreams begin

 Posted: 10 May 2012 12:08:00 pm    Post subject: I know repeat K=45 is pretty standard.. I have seen Repeat in every program that uses sprite movement. as I understood it, they are the same speed._________________
turiqwalrus

New Member

Joined: 18 Nov 2010
Posts: 95
Location: Eggplant shopping! :P

Posted: 10 May 2012 01:52:00 pm    Post subject:

 Aes_Sedia5 wrote: I know repeat K=45 is pretty standard.. I have seen Repeat in every program that uses sprite movement. as I understood it, they are the same speed.

In which case Repeat K=45 should be used, as it is more understandable...
_________________
This signature is completely empty

except for this
and this
JOIN THE WFCLFY!
blue_bear_94

Member

Joined: 20 Apr 2012
Posts: 162

 Posted: 10 May 2012 02:47:16 pm    Post subject: What if K is already 45?_________________Do NOT click any links!
merthsoft

File Archiver

Joined: 09 May 2010
Posts: 2735

 Posted: 10 May 2012 02:51:07 pm    Post subject: Repeat evaluates the conditional at the end of the loop, rather than the beginning. See http://tibasicdev.wikidot.com/repeat. While does it before, so doing "While K-45" could cause the loop to not run. See http://tibasicdev.wikidot.com/while_________________Shaun
builderboy2005

Member

Joined: 05 Aug 2008
Posts: 122

 Posted: 10 May 2012 02:51:15 pm    Post subject: Repeat loops check their condition at the bottom of the loop instead of at the top like While. Consequently a Repeat loop will always execute at least once, which makes it useful for situations like this where we don't care what K was before the loop. EDIT: Cemetech needs a Ninja notifier like Omni has
zeldaking

Power User

Joined: 31 Jul 2011
Posts: 470
Location: Utah

 Posted: 10 May 2012 05:44:20 pm    Post subject: Yeah the getkey resets K to zero the first time through. I tried while loop, and a for( loop the latter taking the most bytes. Code: ``` :for(K,0,45 :getkey->K :end ```
KermMartian

Joined: 14 Mar 2005
Posts: 55751
Location: Earth, Sol, Milky Way

 Posted: 11 May 2012 11:51:10 am    Post subject: Indeed, that's a quite clever way to do it, but sadly not sufficiently optimal for all its slyness. I know I'm beating my own drum too much about this, but I feel I wrote up a fairly thorough guide to optimization as Chapter 10 of my book, and I detailed things like the differences between While and Repeat and the proper places to use each. At any rate, I'd say that the code as presented is a quite nice little program, and about as optimized as you'd want to or be able to get for something like this._________________
Xeda112358

Power User

Joined: 09 Nov 2010
Posts: 353

 Posted: 08 Jun 2012 06:59:10 am    Post subject: This is a little more optimised: Code: ``` :1→A:1→B :Repeat K=45 :getKey→K :If Ans                      ;Added this in so as not to be blinking so much. :ClrHome :Output(B,A,"* :max(1,min(16,A+(K=26)-(K=24→A :max(1,min(8,B+(K=34)-(K=25→B :End ```
KermMartian

Joined: 14 Mar 2005
Posts: 55751
Location: Earth, Sol, Milky Way

 Posted: 08 Jun 2012 08:03:00 am    Post subject: Mmm, that is indeed better. I had held off on the min-max form for the sake of possible confusion, but you're absolutely right that it's smaller. Out of curiosity, have you checked what the relative speed of that is? In this case I'd expect it to be a negligible difference, I suppose._________________
Xeda112358

Power User

Joined: 09 Nov 2010
Posts: 353

 Posted: 08 Jun 2012 08:06:51 am    Post subject: I don't have the timings, but I do imagine it is negligible. min() and max() are fairly fast to compute.
zeldaking

Power User

Joined: 31 Jul 2011
Posts: 470
Location: Utah

 Posted: 08 Jun 2012 09:12:35 am    Post subject: hmmm, I have never used max( or min( before. What is the syntax?
KermMartian

Joined: 14 Mar 2005
Posts: 55751
Location: Earth, Sol, Milky Way

Posted: 08 Jun 2012 11:37:57 am    Post subject:

 zeldaking wrote: hmmm, I have never used max( or min( before. What is the syntax?
min(X,Y) will find and return the smaller of X and Y; max(X,Y) will find and return the larger of X and Y. If you work with lists instead, min({a,b,c,...z}) or min(L1) will return the smallest value of the list, and symmetrically, max(list) will return the largest value in the list.
_________________

 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
 Page 1 of 1 » All times are GMT - 5 Hours

 Jump to: Select a forum Announcements----------------Cemetech AnnouncementsCemetech LabsContests General Discussion----------------Technology & Calculator Open Topic-- Electronics/Hardware Development-- Calculator HardwareYour ProjectsGeneral Open Topic-- Politics & Rants-- Reviews-- Humour/Jokes Cemetech's Projects----------------Doors CSSourceCoderMember Features-- TI-Freak8x-- Merthsoft-- GrammerOther & Upcoming Projects-- The BASIC Elite-- mobileTunes-- CALCnet 2.2-- SuggestionsProgramming the TI-83 Plus/TI-84 PlusUsing the TI-83 Plus/TI-84 PlusWebsite Programming & Design----------------General Programmingz80 AssemblyTI-BASICCasio Prizm/FX Development & ProgrammingWebsite Markup & ScriptingGraphics1337 Programming Tips Building with Blocks----------------FreeBuild, LEGO, and Minecraft-- FreeBuild General-- Suggestions & Troubleshooting-- Content & Gallery-- Servers & Activities
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.033812 seconds.