Welcome to DrScheme, version 4.2.1 [3m]. Language: Swindle; memory limit: 128 megabytes. ======================================= CMPU-145, Spring 2013 Solutions! Asmt. 5 ======================================= ------------------------ 1: Generate all permutations of a given set (list) ------------------------ (gen-all-perms '(1 2)) ====> ((1 2) (2 1)) (gen-all-perms '(a b c)) ====> ((a b c) (a c b) (b a c) (b c a) (c a b) (c b a)) (length (gen-all-perms '(1 2 3 4 5 6 7))) ====> 5040 (* 7 6 5 4 3 2 1) ====> 5040 ------------------------ 2: Generate all possible ways of choosing k items from a given list ------------------------ (gen-all-ways-of-choosing-k-items '(1 2 3 4) 2) ====> ((1 2) (1 3) (1 4) (2 3) (2 4) (3 4)) (gen-all-ways-of-choosing-k-items '(A B C) 2) ====> ((A B) (A C) (B C)) (gen-all-ways-of-choosing-k-items '(1 2 3 4 5 6) 3) ====> ((1 2 3) (1 2 4) (1 2 5) (1 2 6) (1 3 4) (1 3 5) (1 3 6) (1 4 5) (1 4 6) (1 5 6) (2 3 4) (2 3 5) (2 3 6) (2 4 5) (2 4 6) (2 5 6) (3 4 5) (3 4 6) (3 5 6) (4 5 6)) (length (gen-all-ways-of-choosing-k-items '(1 2 3 4 5 6 7 8 9 10) 4)) ====> 210 (/ (* 10 9 8 7) (* 4 3 2 1)) ====> 210 ------------------------ 3: Poker hand with a flush! ------------------------ *num-flushes* ====> 5148 *prob-flush* ====> 0.0019807923169267707 (gen-and-test 100000 rand-poker-hand has-flush?) ====> 0.00188 (gen-and-test 100000 rand-poker-hand has-flush?) ====> 0.00194 (gen-and-test 100000 rand-poker-hand alt-has-flush?) ====> 0.00184 (gen-and-test 100000 rand-poker-hand alt-has-flush?) ====> 0.00189 ------------------------ 4: Bridge hand with 5-4-2-2- distribution of suits ------------------------ *num-hands-with-5-4-2-2* ====> 67182326640 *num-13-card-hands* ====> 635013559600 *prob-5-4-2-2-distn* ====> 0.10579668043989277 (gen-and-test 100000 gen-bridge-hand is-5-4-2-2-distn?) ====> 0.10706 >