i was wondering if there was a more efficient way to make a deck of cards than:


Code:

:52→dim(L1
:Disp "CREATING DECK...
:For(A,1,4
:0→L1(A
:End
:For(A,5,8
:1→L1(A
:End
:For(A,9,12
:2→L1(A
:End
:For(A,13,16
:3→L1(A
:End
:For(A,17,20
:4→L1(A
:End
:For(A,21,24
:5→L1(A
:End
:For(A,25,28
:6→L1(A
:End
:For(A,29,32
:7→L1(A
:End
:For(A,33,36
:8→L1(A
:End
:For(A,37,40
:9→L1(A
:End
:For(A,41,44
:10→L1(A
:End
:For(A,45,48
:11→L1(A
:End
:For(A,49,52
:12→L1(A
:End
:4→dim(L2
:For(A,1,4     //for the suits
:For(B,1,A
:B→L2(A
:End
:End
Just off the top of my head:


Code:
For(A,0,12
For(B,1,4
A->L1(4A+B
End
End
:For(A,1,4     //for the suits
:For(B,1,A
:B→L2(A
:End
:End
Give me a sec and I can optimize it even more.
thanks i did not even think of that.
Wait, I can get it further:


Code:
For(A,0,12
For(B,1,4
A->L1(4A+B
B→L2(4A+B
End
End
thanks again. except the list 2 was not right. it created a sequence of 1-4 13 times so i am going to have to use the one i had.
I figured that was what you wanted....seeing as how the L1 created each card four times.
Or just store 0-51 into a list and get suit and rank this way:

suit is iPart(A/13
rank is 13fPart(A/13
oh well just a simple mis understanding. i wanted the L2 though so that i could just randomize an integer and than take the list element equal to that number.


Edit: i might use your way though chipmaster because it might save me a lot of memory doing the checks so that there are not more than four of each suit.
I agree. A quick seq( command would totally pwn that routine. I was just trying to stay as true to his code as possible.
how exactly would i do the seq( command. i wrote it like this:

Code:

seq(A,A,0,12->L1


but it only generates one sequence of twelve numbers.
You could just seq it to 51 and use Kirb's method. Or you could loop the seq( if you really want to do it your way.
i think i will use kirbs way. it will take up less space and make it faster.

tried it with my program and it runs about 20 times faster.
Very Happy Nice job on the optimizations, guys. I happen to think that Kirb's way is probably the best method in this case.
is there a way i can get a random list element without having to do:


Code:

randint(1,52->A
L1(A->A
You can shorten it to:
Code:
L1(randInt(1,52->A
if that's what you mean.
It depends on if the card drawings are independent or not. If they are independent (each time you have a 1/52 chance of drawing a 2 of hearts) than you can just do


Code:
randInt(1,52,52


If they are dependent, than that's the best way I can think of, well other than the obvious optimization of:


Code:
L1(randInt(1,52->A


Edit: Look at the post times. Lol, great minds think alike Smile
so i should just ditch the list and just get random numbers for the cards that will be used for the round.
It really depends on what you are trying to do. If you could explain exactly what you are going for, I could offer a suggestion. I have a feeling, though, that you want the cards to be dependent, and that would necessitate the list.
well i am trying to create a poker game and i wanted to try to make a more efficient way of getting card values than just using randint(
That'd be dependent (as you wouldn't want repeats out there). Better stick with randInt and a list.
  
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