r.braatz

8 Reputation

2 Badges

15 years, 104 days

MaplePrimes Activity


These are replies submitted by r.braatz

Thank you for the reply, here is what I'm using:

with(Statistics):randomize():
face := [A,1,2,3,4,5,6,7,8,9,10,J,Q,K];
suit := [Heart,Diamond,Club,Spade];
predeck := map(suit,face);
deck :={seq(seq(predeck [ a,b ], a = 1..13),b = 1..4)};
Sim := proc ( hands )
             local n := 0, getindex1, card1, deck1, getindex2, card2;
             while n <= hands
             do n := n +1; 
                  getindex1 := rand(1..52); 
                  card1 := deck [ getindex1( ) ]; 
                  deck1 := deck minus {card1};
                  getindex2 := rand (1..51);
                  card2 := deck1 [ getindex2( ) ];
                  print (card1 + card2);
           end do;
           end:

Sim(10);  This will give me a print of ten 2-card hands.  However, I can't find a way to work with this printout.  I'd like to take Sim(1000) or so and then convert these into values by the following functions(see below) so that I can work some statistics on the data to determine most likely hands and other items.  I've never had a programming course, so I'm certain that my code is not efficient as I've been trying to copy what others have done; so I apologize for this.
          Heart := x->x; Spade:=x->x; Diamond:=x->x; Club:=x->x; A:=11; J:=10; Q := 10; K:=10:

Rather than "print", I've tried the following command on the print line:
                 list := list, [card1 + card2]
This gives me an output, but I believe "hides" the actualy size.  When I try to grab one element from the Sim(10), it gives "too many levels of recursion". 

Again, I really just want it to generate black jack hands that I can then work with using some basic stastics.  If you have any advice on how to improve the code, I would be very greatful.  Thanks again for the previous help.


                   
                  

Thank you for the reply, here is what I'm using:

with(Statistics):randomize():
face := [A,1,2,3,4,5,6,7,8,9,10,J,Q,K];
suit := [Heart,Diamond,Club,Spade];
predeck := map(suit,face);
deck :={seq(seq(predeck [ a,b ], a = 1..13),b = 1..4)};
Sim := proc ( hands )
             local n := 0, getindex1, card1, deck1, getindex2, card2;
             while n <= hands
             do n := n +1; 
                  getindex1 := rand(1..52); 
                  card1 := deck [ getindex1( ) ]; 
                  deck1 := deck minus {card1};
                  getindex2 := rand (1..51);
                  card2 := deck1 [ getindex2( ) ];
                  print (card1 + card2);
           end do;
           end:

Sim(10);  This will give me a print of ten 2-card hands.  However, I can't find a way to work with this printout.  I'd like to take Sim(1000) or so and then convert these into values by the following functions(see below) so that I can work some statistics on the data to determine most likely hands and other items.  I've never had a programming course, so I'm certain that my code is not efficient as I've been trying to copy what others have done; so I apologize for this.
          Heart := x->x; Spade:=x->x; Diamond:=x->x; Club:=x->x; A:=11; J:=10; Q := 10; K:=10:

Rather than "print", I've tried the following command on the print line:
                 list := list, [card1 + card2]
This gives me an output, but I believe "hides" the actualy size.  When I try to grab one element from the Sim(10), it gives "too many levels of recursion". 

Again, I really just want it to generate black jack hands that I can then work with using some basic stastics.  If you have any advice on how to improve the code, I would be very greatful.  Thanks again for the previous help.


                   
                  

Page 1 of 1