Re: TIB: mixing up a list


[Prev][Next][Index][Thread]

Re: TIB: mixing up a list




>Okay, the problem is that towards the end, most elements of the list are 
>full, therefore it can take a while to find an element that is empty. If 
>you try something like this, I think you'll find it's faster:
>
>Fill(0,cards)
>For(a,1,26
>Lbl gn
>randint(1,52)\->\b
>if cards(b)<>0                 <> means not equal to
>goto gn
>1\->\cards(b)
>end
>For(a,1,52
>if cards(a)=0
>2\->\cards(a)
>End
>
>The difference is that the second for loop only scans the whole list and 
>fills the empty elements with 2's, because the 1's are
>already in.
>
>James Vernon
>jimbob_v@hotmail.com

Good point, but here's another idea that can eliminate the
second loop. Just change your fill and your first "If".
Oh, and while the list is also on this subject, let's avoid
the Goto's as well.


Fill(2,cards)
For(a,1,26)
randint(1,52)\->\b
If cards(b)=2
Then
1\->\cards(b)
Else
a-1\->\a
End
End

If your calculator doesn't have the Else command, or you think
this may improve speed, you can replace the enire If statement
(the part I indented) with two of them.

If cards(b)=2
1\->\cards(b)
If cards(b)=1
a-1\->\a

And a further note about RandInt.. If your calculator doesn't
have that command, try

rand(52)  *works on TI-92, and thus the 89 and 92+

or else multiply the rand function with 26 and take the integer

int (52rand)

If you use a TI-85, the parentheses aren't necessary but it
is a good idea if you wish to use it for other calcs such as
the TI-86.

Good luck, and keep up the programming!

Tavis


_______________________________________________________________
Get Free Email and Do More On The Web. Visit http://www.msn.com