today in class i was messing around with the random number things and it is one byte smaller and a little bit faster too:

Code:

ipart(10rand


than it is to

Code:

randint(0,9


but that is only for numbers 0-9
And you can also do

Code:
ipart(9rand

instead of

Code:
randint(0,8

Smile
hey, thats a pretty cool optimization
lafferjm wrote:
today in class i was messing around with the random number things and it is one byte smaller and a little bit faster too:

Code:

ipart(10rand


than it is to

Code:

randint(0,9


but that is only for numbers 0-9
I'm already reported this on the site before. Smile
Heh, I've been using that for a while actually. By the way int( is faster then iPart( (if you want documentation tell me).
Super Speler wrote:
Heh, I've been using that for a while actually. By the way int( is faster then iPart( (if you want documentation tell me).
I too came to the same conclusion. Very Happy
Dang...maybe I should test code before I use it Smile
KermMartian wrote:
I'm already reported this on the site before. Smile


Sorry didn't know. At least i discovered something new that i didnt know before.
lafferjm wrote:
KermMartian wrote:
I'm already reported this on the site before. Smile


Sorry didn't know. At least i discovered something new that i didnt know before.

agreed, self investigation is one of the best parts of learning to program. and of course sharing useful tips you discover is always good as well!
Even for those self-proclaimed advanced programmers...

*looks at self* Wink

Oh, and a theory, not actually tested, of mine:

If you are using a For( loop that looks like


Code:
For(X,1,28+2(X>8
or
Code:
 For(X,1,Y


Would it be faster to do


Code:
For(X,28+2(X>8),1,-1
or
Code:
For(X,Y,1,-1


Yeah, it takes up a few more bytes, but if it's a speed-critical loop, then wouldn't it benefit you?

(This is purely theoretical, I don't know if it actually is faster).
Harrierfalcon: I doubt that it is faster.

lafferjm: Nice finding. Smile

I'm also guessing that it might be faster to do:

If A<7

instead of

If A<=6

If A is an integer.
As I see you guys want to check time codings, then perhaps you'd be interested by this file of mine or that file of Arthur O'Dwyer.
Fallen, I couldn't find any testing of ">" vs. ">=" or the like in the Command Timings.
yes the above methods are the only way to do it on the TI82, no randint( feature.
I have a question about what i found. Why is it smaller if it is more tokens than randint(?
randInt( 1
0 2
, 3
9 4

int( 1
rand 2
9 3

There's me counting each byte.

Also interesting optimization I found:
Instead of 10*(blah+blah)/7 you can do .7^-1(blah+blah
lafferjm wrote:
I have a question about what i found. Why is it smaller if it is more tokens than randint(?


They have the same number of tokens, but the difference is that randInt() is a 2 byte token (which Super Speler screwed up Razz ), whereas all the rest are 1 byte tokens. There is the difference in size Smile

randInt(0,9
randInt( == 2 bytes
0 == 1 byte
, == 1 byte
9 == 1 byte
Total: 5 bytes

ipart(10rand
ipart == 1 byte
1 == 1 byte
0 == 1 byte
rand == 1 byte
Total: 4 bytes
should this be put in l337 programming tips? its a good thing to know, and im sure tons of intermediate people wouldnt know about it.
Super Speler wrote:
randInt( 1
0 2
, 3
9 4

int( 1
rand 2
9 3

There's me counting each byte.

Also interesting optimization I found:
Instead of 10*(blah+blah)/7 you can do .7^-1(blah+blah
If you're going for speed instead of space, work out .7^-1 to the accuracy you need first.
You know that ^-1 is one byte right...
  
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.

» Go to Registration page
Page 1 of 2
» All times are UTC - 5 Hours
 
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

 

Advertisement