CMPU-145, Spring 2013 Asmt. 7 Due: Wed., May 8 @ 5:00 p.m. ==> Download the following files into your working directory for this assignment: asmt-helper.txt asmt5-helper.txt asmt7-helper.txt You only need to load asmt7-helper.txt because it will take care of loading the others. ------------------------------------------------------------------------- NOTE: Unlike the examples shown in these instructions, all of YOUR examples will use the TESTER function!! ------------------------------------------------------------------------- PROBLEM 1. See the functions defined in asmt7-helper.txt. PART A: Randomly generating a 5-card hand that has a full house. Define a function, called RAND-FULL-HOUSE, that takes no inputs. It should generate as its output a list of five cards (i.e., numbers from 0 to 51) that has a "full house" (i.e., 3 cards of one rank plus two cards of another rank). ==> This function must not play favorites! Each hand that has a full house should be equally likely. One way of implementing this function is to repeatedly deal 5-card hands until one shows up with a full house. Don't do that! It is *extremely* inefficient!! Recall how we computed the probability of a full house. (Go look it up!) We consider the number of ways of choosing ranks and suits. Here, you'll do the same thing, except that instead of determining the number of choices, you'll actually *make* a choice (randomly). ==> The functions in asmt5-helper.txt and asmt7-helper.txt (e.g., cards->string) should be helpful! > (cards->string (rand-full-house)) "6C 6S 6D 2D 2H " > (cards->string (rand-full-house)) "10S 10H 10D 3H 3D " PART B: Getting a hand with at least one card in each suit. Let E be the event that a hand of five cards has at least one card in each suit. Define a function, HAS-EVEN-DISTN?, that takes a list of cards (i.e., numbers from 0 to 51) as its only input. It should return #t if those cards have at least one of each suit. (The SUIT function should come in handy.) It should return #f otherwise, as illustrated below. > (define cards1 (rand-poker-hand)) > (cards->string cards1) "AS 2S 8C 2H 6H " > (has-even-distn? cards1) #f > (define cards1 (rand-poker-hand)) > (cards->string cards1) "KC 6S AS 9D 8H " > (has-even-distn? cards1) #t PART C: Computing some probabilities!! Let E be the event that a hand of five cards has even distribution (i.e., at least one card from each suit). Let F be the event that a hand of five cards has a full house. Define the following global variables: *prob-even-distn* <--- prob(E) *prob-full-house* <--- prob(F) *prob-even-distn-and-full-house* <--- prob(E INTERSECT F) = prob(E AND F) *prob-even-distn-given-full-house* <--- prob(E GIVEN F) = prob(E|F) *prob-full-house-given-even-distn* <--- prob(F GIVEN E) = prob(F|E) HINT: Recall the definitions: prob(F|E) = prob(F AND E) / prob(E) prob(E|F) = prob(E AND F) / prob(F) If you know two of the probabilities in either of these equations, you can solve for the third. Some of them are harder than others to compute directly. --> If you get stuck on one or more, continue to part D. GEN-AND-TEST may provide some clues. We already know (from class) that prob(F) is about .00144. But you should compute the actual value. NOTE: Use TESTER expressions (e.g., (tester '*prob-full-house*)) to display the values of these variables. NOTE: Also, use TESTER to show the value of: prob(E)*prob(F) This should NOT be the same as prob(E AND F) because these two events are NOT independent!! PART D: Using GEN-AND-TEST Use GEN-AND-TEST, where RAND-FULL-HOUSE is the generator function, and HAS-EVEN-DISTN? is the testing function. Which of the above probabilities should this estimate?? PART E: Randomly generating a hand with even distribution. Define a function, called RAND-EVEN-DISTN, that takes no inputs. It should return as its output a list of five randomly chosen cards with at least one card from each suit. NOTE: Do NOT choose the easy-but-very-inefficient route of randomly generating hands until you find one that has even distribution! Think about how you computed the number of possible hands with even distribution! Also, each such hand should be equally likely!! Don't play favorites! > (cards->string (rand-even-distn)) "10D 3D 6C 9H QS " > (cards->string (rand-even-distn)) "9D KD 8C 2H QS " > (cards->string (rand-even-distn)) "2H 3H 10C 6D JS " PART F: Using GEN-AND-TEST one more time! The function, HAS-FULL-HOUSE?, seen in Lab 8, is included in the asmt7-helper.txt file. So, it is available for use. Use GEN-AND-TEST with RAND-EVEN-DISTN as the generating function and HAS-FULL-HOUSE? as the testing function. Which of the probabilities from part C should this estimate? ================= As usual, turn in printouts of your definitions and interactions files. And submit all files electronically using submit145. ================= Hey! That's the last assignment!