Hey everyone, I have a quick question regarding optimization in ti-basic. Right now I'm trying to make the least memory, fastest random card deck routine. So it pretty much shuffles a deck. The suites are stored as 1,2,3 or 4 as Hearts, Diamond, Spade, Clubs respectively. I don't care how in memory they are stored and right now I have the number of the card in list CN and suites in list CT here is my routine.

Code:

:randIntNoRep(1,52->L1
:52->dim(L CN    ;L is list
:52->dim(L CT
:For(T,1,4    ;loop for suites
:For(N,1,13
:L1(13T-13+N->θ
:N->L CN(θ
:T->L CT(θ
:End
:End

Lets see what you guys can come up with!
it looks like axe...

but hey its interesting
i didn´t thought about something like this.
i would use labels and strings and lists...
but this is faster:D
*turns brain from c++ to TI Perl*

Well my TI Perl is a bit rusty but it looks really pretty good. I dont see any way to make it too much smaller, but i am Sure Weregoose could prove me wrong there.

edit: funny thing is, on this routine i just had to do it for a programming project for COSC 1030 advanced c++ and i optimize pretty well as force of habit from C++ and this takes less code and looks faster (for ratio of the system) which is kinda surprising. Very Happy
Hey thanks! I didn't think about the randIntNoRep( idea until messing around with several ideas. I am happy how it worked out.
I am also wondering if there is anyway similar to this in axe, but since the randIntNoRep( is not a valid token I am trying to come up with another way.
What I would do is :

Code:
4⁻¹randIntNoRep(0,51

Then you use 4fPart() on the list element to figure out the suit (this will return a value of 0,1,2, or 3) and then use iPart() on the list element to figure out the card (this will return a value from 0 to 12).

I hope this helps and is more efficient/faster!

EDIT: Replaced .25 with 4⁻¹ since the speed difference is not really noticeable by humans and it is a byte smaller.
Hmm I didn't think of that. I'm not that good at Ti-Basic yet. Thanks for that!
  
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 1
» 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