MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?
-
Upload
bernard-griffin -
Category
Documents
-
view
219 -
download
2
Transcript of MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?
![Page 1: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/1.jpg)
MASTERMIND
Did anyone play the game over the weekend? Any thoughts on strategy?
![Page 2: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/2.jpg)
Combinatorics Review
CSC 172
SPRING 2004
LECTURE 12
![Page 3: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/3.jpg)
Assignments With Replacement
Example: PasswordsAre there more strings of length 5 built from three
symbols or strings of length 3 built from 5 symbols?What would make a better password?
4 digit “pins”3 letter initials
![Page 4: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/4.jpg)
In general
We are given n “items”, to each we must assign one of k “values”Each value may be used any number of timesLet W(n,k) be the number of ways
How many different ways may we assign values to the items?“Different ways” means that one or more of the items get different values.
![Page 5: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/5.jpg)
Inductive Definition
Basis:
W(1,k) == k
Induction:
If we have n+1 items, we assign the first one in one of k ways and the remaining n in W(n,k) ways
![Page 6: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/6.jpg)
Recurrence
W(1,k) = k
W(n+1,k) = k * W(n,k)
T(1) = k
T(n) = k * T(n-1)
Easy expansion
T(n) = kn
![Page 7: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/7.jpg)
Example: Are there more strings of length 5 built from three symbols or strings of length 3 built from 5 symbols?
Length 5, from 3 “values” = {0,1,2}
“items” are the 5 positions
N = 35 = 243
Length 3, from 5 “values” = {0,1,2,3,4}
“items” are the 3 positions
N = 53 = 125
![Page 8: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/8.jpg)
Example: Are there more 4-digit pins, or 3 letter initials?
Length 4, from 10 “values” = {0,1,2,3,4,5,6,7,8,9}
“items” are the 4 positions
N = 104 = 10000
Length 3, from 26 “values” = {a,b,c,…,x,y,z}
“items” are the 3 positions
N = 263 = 17576
![Page 9: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/9.jpg)
MASTERMIND
How many codes? N colors M positions
Can you build an array of unknown
Dimensionality?
![Page 10: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/10.jpg)
Exercise (aside)
Can you write
public int blackPegs(
String [] correct, String[] guess){
// return the number of correct colors
// in the correct positions
}
![Page 11: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/11.jpg)
Exercise (aside)
Can you write
public int whitePegs(
String [] correct, String[] guess){
// return the number of correct colors
// in the incorrect positions
}
![Page 12: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/12.jpg)
Permutations
Example: “SCRABBLE”
- start with 7 letters (tiles)
- how many different ways can you arrange them
- we don’t care about the word’s legality
![Page 13: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/13.jpg)
Scrabble
We can pick the first letter to be any of the 7 tilesFor each possible 1st letter, there are 6 choices of
second lettersOr, 7*6 = 42 possible two letter prefixesSimilarly, for each of the 42, there are 5 choices of
the third letter. 42 * 5 = 210, and so onTotal choices = 7*6*5*…*1 = 7! = 5040
In general, there are n! permutations of n items.
![Page 14: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/14.jpg)
Ordered Selections
Suppose we want to begin Scrabble with a 4 letter word? How many ways might we form the word from our 7 distinct tiles?
For each possible 1st letter, there are 6 choices of second letters 7*6 = 42 possible two letter prefixes
For each of the 42, there are 5 choices of the third letter. 42 * 5 = 210
For each of the 120, there are 4 choices of the third letter. 210 * 4 = 840
![Page 15: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/15.jpg)
In general
(n,m), the number of ways to pick a sequence of m things out of n
== n*(n-1)*(n-2)*…*(n-m+1)
== n!/(n-m)!
1*...*)1(*)(
1*...*)(*)1(*...*)2(*)1(*),(
mnmn
mnmnnnnmn
![Page 16: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/16.jpg)
Combinations
Suppose we give up trying to make a word and want to throw 4 of our 7 tiles back in the pile? How many different ways can we get rid of 4 tiles?
Ordered selection 7!/(7-4!) = 840
However, we don’t care about order.
So, how many ways are there to order 4 items?
4! = 24
840/24==35
== 7!/((7-4)!4!) = 35
![Page 17: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/17.jpg)
In general
“n choose m”
!)!(
!
mmn
n
m
n
![Page 18: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/18.jpg)
Recursive Definition for n choose mWe want to choose m things out of n, we can either
take or reject the first item.
If we take the first, then we can take the rest by choosing m-1 of the remaining n-1
We can do this in (n-1) choose (m-1) ways
OTOH, if we reject the first item, then we can get the rest by choosing m of the remaining n-1
We can do this in (n-1) choose m ways
![Page 19: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/19.jpg)
Inductive Definition
Basis: for all n there is only one way to choose all or
none of the elements
Induction:
for 0 < m < n
10
n
nn
m
n
m
n
m
n 1
1
1
![Page 20: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/20.jpg)
Proving Inductive Definition = Direct Definition
What is the induction parameter?
Zero for the basis case
decreases in the inductive step
Complete induction on m(n-m)
m
n
m
nmnc
1
1
1),(
Prove: c(n,m) = n!/((n-m)!m!)
![Page 21: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/21.jpg)
Basis
If m(n-m) == 0, then either m == 0 or m == n
If m == 0,
then n!/(n-m)!m! == n!/n! = 1 = c(n,0)
If m == n,
then n!/(n-m)!m! == n!/n! = 1 = c(n,n)
![Page 22: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/22.jpg)
Induction
By definition c(n,m) = c(n-1,m-1) + c(n-1,m)
Assume,c(n-1,m-1) = (n-1)!/((n-m)!(m-1)!)
c(n-1,m) = (n-1)!/((n-m-1)!m!)
Add the left sides == c(n,m), by definition
Add the right sides == n!/(n-m)!m!, clearly
![Page 23: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/23.jpg)
)!)!1((
)!1(
))!1()!((
)!1(
mmn
n
mmn
n
!)!1()!1()!(
)!1()!()!1(!)!1()!1(
mmnmmn
mmnnmmnn
!)!1()!(
)!()!1()!1()!1(
mmnmn
mnnmmnn
!)!(
)()!1()!1(
mmn
mnnmn
!)!(
)!1()!1()!1(
mmn
nmnnmn
!)!(
!
!)!(
)!1(
mmn
n
mmn
nn
![Page 24: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/24.jpg)
Reminders
Midterm is Tuesday – in class Project is due before you go on Spring break For workshop read Weiss Section 13.1
The Josephus Problem I will be out, most of next week
Thursday’s guest lecture will involve “game AI” 7.7 & 10.2 (alpha-beta pruning)
![Page 25: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/25.jpg)
Midterm Closed book, notes Calculators will not be necessary – no laptops Proof by induction Solve recurrence relations Big-Oh proof Big-Oh analysis of some code Linked list programming Stacks, queues, arrays Recursion/backtracking programming analysis Sorting (merge, quick, insertion, shell) Combinatorics
![Page 26: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/26.jpg)
Orders With Some Equivalent ItemsIn real life, we play Scrabble with duplicate letters
Suppose you draw {S,T,A,A,E,E,E} at star, how many 7-letter “words” can you make.
Similar to permutations, but now, some are indistinguishable, because of duplicates
Trick: we can mark the letters to make them distinguishable S,T,A1,A2,E1,E2,E3
Then we get 7!=5040 ways
![Page 27: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/27.jpg)
How much “sameness”
But some order are the same
E3TA1E1SA2E2 == E3TA2E1SA1E2
The two As can be ordered in 2! = 2 ways
The three Es can be ordered in 3! = 6 ways
So, the number of different words is
7!/2!3! = 540/(2*6) = 420
![Page 28: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/28.jpg)
In general
The orders of n items with groups i1,i2,…,ik equivalent items is
n!/(i1!i2!..ik!)
![Page 29: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/29.jpg)
Items into Bins
Suppose we throw 7 dice (6 sided). How many outcomes are there?
Place each of 7 items into one of 6 bins The tokes are the dice
The bins are then number of dice
Putting the second token into bin 3 means that the second die shows 3
![Page 30: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/30.jpg)
TrickImagine 5 markers, denoted “*” that represent
separation between bins, and 7 tokens “T” that represent dice
The string “*TT**TTT*T*T” corresponds to no 1s, two 2s, no 3s, three 4s, a 5 and a 6
How many such strings?
“orders with identical items”
12 items, 5 of type “*”, 7 of type “T”
12!/5!7! = 792
![Page 31: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/31.jpg)
In general
The number of ways to assign n items to m bins
The number of orders of n-1 markers and n tokens
n
mn
nm
mn 1
!)!1(
)!1(
We are picking n out of the possible n+m-1positions for the tokens
![Page 32: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/32.jpg)
Several kinds of items into Bins
Order in bin can be either important (queues) or not
![Page 33: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/33.jpg)
Several kinds of items, order within bin unimportant
If we have items of k colors, with ij items of the jth color, then the number of distinguishable assignments into m bins is:
j
jk
j i
im 11
Example: 4 red dice, 3 blue dice, 2 green dice6 bins
176,1482
7
3
8
4
9
![Page 34: MASTERMIND Did anyone play the game over the weekend? Any thoughts on strategy?](https://reader036.fdocuments.us/reader036/viewer/2022062421/56649cf85503460f949c92a1/html5/thumbnails/34.jpg)
Order important
If there are m bins into which ij items are placed and order within the bin matters
Imagine m-1 markers separating the bins and ij tokens of the jth type
By “orders with identical items”
jkj im
mn
1)!1(
)1(