C ODEBREAKER Class discussion.

Slides:



Advertisements
Similar presentations
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Advertisements

Brian Duddy.  Two players, X and Y, are playing a card game- goal is to find optimal strategy for X  X has red ace (A), black ace (A), and red two (2)
Control Structures FOR Statement Looping.
TESTING, Testing Strategies for taking Standardized Tests.
THE ACT TEST Austin English 11. What’s on the Test?????? in English 1.45 minutes – 75 items 1.Tests you knowledge on: Punctuation USAGE & GrammarMECHANICS.
Image segmentation Prof. Noah Snavely CS1114
3 Strategies to Tackling Multiple Choice questions 1.Plug in a number 2.Back-solving 3.Guessing.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Maths quiz KS 2: Use sequence in programs. Today we are learning about: Programs & Selection ●I can explain what selection is ●I can write a program using.
Multiplying Decimals 12/7/2015. To Multiply: You do not align the decimals. Instead, place the number with more digits on top. Multiply Count the number.
CMSC 104, Version 8/061L24Searching&Sorting.ppt Searching and Sorting Topics Sequential Search on an Unordered File Sequential Search on an Ordered File.
Exponential Functions
Problem Solving: Brute Force Approaches
SAT Prep Lesson # 1 EQ: What do I need know about time management to be successful on the SAT?
Welcome to the random dots experiment!
CSSE 230 Day 25 Skip Lists.
CSE15 Discrete Mathematics 02/08/17
Recitation #3 Tel Aviv University 2016/2017 Slava Novgorodov
Exponential Functions
mastermind: last details
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
Multiply using Distributive Property
David Kauchak CS52 – Spring 2016
Chapter 7 Sorting Spring 14
Python - Iteration Iteration
CHAPTER 6 PROBABILITY & SIMULATION
Exponential Functions
ENGLISH TEST 45 Minutes – 75 Questions
CS 4700: Foundations of Artificial Intelligence
Session 8 Exam techniques
Games with Chance Other Search Algorithms
How to be successful taking Multiple Choice tests.
Problem Solving: Brute Force Approaches
Understanding Randomness
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Discrete Structures for Computer Science
Exponential Functions
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Exponential Functions
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Searching and Sorting Topics Sequential Search on an Unordered File
Logical assertions assertion: A statement that is either true or false. Examples: Java was created in The sky is purple. 23 is a prime number. 10.
Building Java Programs
UMBC CMSC 104 – Section 01, Fall 2016
Searching and Sorting Topics Sequential Search on an Unordered File
Components 96 Pig cards How are they different?
Counting Techniques and Some Other Math Team Strategies
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Exponential Functions
Exponential Functions
DO NOW 3/15/2016 Find the values
Why do we need to take these tests?
General Test-Taking Strategies
State-Space Searches.
State-Space Searches.
Test Taking Strategies
Reading Strategies and Techniques
Exponential Functions
Simultaneous Equations
Effective Questioning
State-Space Searches.
Directions to play game
Game Description Player 1: Decides on integer x > 0
Facial Hair.
Starter Look at the hand-out.
CS51A David Kauchak Spring 2019
Count to 100, identify number, estimate
Minimax Trees: Utility Evaluation, Tree Evaluation, Pruning
Presentation transcript:

C ODEBREAKER Class discussion

Question 1 Strategies for codemaker

What did you do as codemaker? When you were playing as codemaker, what strategy did you use to pick a code?

question 2 number of codes

How many codes are there? Anyone have a guess how many different possible codes there are?

Number of codes If we used just 1 digit, there would be 6 possible codes. is it a 5? is it a 1? is it a 3? ? is it a 2? is it a 6? is it a 4?

What if there are 2 digits? If 1st digit is 1 6 possible choices for 2nd digit 1 2 1 3 4 6 5 6 possibilities for first number 6 possibilities for second number 6 * 6 = 36 possible combinations 11 12 13 14 15 16 21 22 23 24 25 26 31 32 33 34 35 36 41 42 43 44 45 46 51 52 53 54 55 56 61 62 63 64 65 66

What if more than 2 digits in code? 6 possibilities if only 1 digit 6 * 6 = 36 (62) 6 * 6 * 6 = 216 (63) 6 * 6 * 6 * 6 = 1296 (64) – Mastermind So there are more than 1000 possible codes!

What if valid numbers in code changes? Assume that instead of 1-6, each number can just be 1-4 4 if only one digit 4 * 4 = 16 (42) 4 * 4 * 4 = 64 (43) 4 * 4 * 4 * 4 = 256 (44) Or if each number could be 1-10 10 * 10 * 10 * 10 = 10,000 (104)

question 3 Codebreaker strategy

What’s a good strategy for the codebreaker? How would you choose your first guess? What would you do next?

A possible strategy Start with a code that has only 2 digits e.g., 4455, 1122, 2266 Let’s walk through some examples to see why this might be good. Assume the code is 1231

Code is 1231 – Guess 1 First guess is 4455 Response is 0-0 What do we know? We should never guess a 4 or a 5 again!

Code is 1231 – Guess 2 We know we should not guess a 4 or a 5. Let’s try 1122 Response is 1-2 What do we know? One correct digit in right location, two correct digits in wrong location Total of three correct digits The code must include either two 1s or two 2s The code must also include either a 3 or a 6 OR one more 1 or 2 (e.g., could be a code like 1211 or 2221)

Code is 1231 – Guess 3 What should we do now? Let’s try 3333 There are various options that are valid We might try other codes to see whether 3 or 6 are included We might try to rearrange numbers to figure out which digit was in the correct location, and move others in the correct location Let’s try 3333 The response is 1-0. So we know the code contains a 3 (in some location) NOTE: more advanced players would likely avoid this guess, as it can’t possibly win. But it is a simple way to find out for sure it the digit 3 is included. An alternative approach is covered later.

Code is 1231 – Guess 4 We know the code contains 1, 2 and 3. It does not contain 4 or 5. Do we need to try 6? 1122 response was 1-2. So three of the digits are 1 and 2 3333 response was 1-0. So one digit must be a 3 That’s four digits…. so no need to try 6 Let’s rearrange our first guess and try 1221 The response is 3-0

Code is 1231 – Guess 5 The response to 1221 was 3-0 so three digits are in the correct location We know that the code also contains a 3 Let’s try putting 3 in one location at a time, first 3221 The response is 2-1 So 3 is NOT the first digit

Code is 1231 – Guess 6 1221 response was 3-0 3221 response was 2-1 Let’s try 3 in the next location: 1321 The response is 2-2 So 3 is NOT the second digit

Code is 1231 – Guess 7 1221 response was 3-0 3221 response was 2-1 Let’s try 3 in the next location: 1231 The response is 4-0 HURRAY! We found the code in 7 guesses.

Alternative sequence for 1231 Here’s a more effective sequence, but it requires slightly more reasoning, especially for guess 3. 4455 => 0-0 (no 4 or 5 in code) 1122 => 1-2 (contains 1,1,2 or 1,2,2 - in some order) 1222 => 2-0 (contains 12_ _) 1213 => 2-2 (we know the digits, fix the order) 1231 => 4-0!

question 4 Strategies for computer players

Are computers better at this? Do you think a computer program could be written that would perform better at this task than we do? Try this (optional, copy and paste into browser): http://csunplugged.mines.edu/mastermind/mastermind.cgi

A computer strategy Here’s one algorithm (step-by-step process) a computer might use. Remember there are 1296 possible codes! Select a random code and ask the codemaker for response. If the codemaker gives a winning response (i.e., 4-0), we have won. Stop. Discard all elements which would no longer be possible under the codemaker’s response. How would we know which ones are no longer possible? Goto step 1

How does the computer eliminate codes? Assume the secret code is 1231. After a few guesses, assume the only possible codes that remain are: 1222 1322 1221 1231 Computer randomly selects 1222. What would the response be?

Eliminating Codes Right! The response would be 2-0 So is 1222 correct? No! Which other codes could be correct, given that response?

Eliminating Codes Could the answer be 1322? Remember the computer guessed 1222. If correct code is 1322, then a “guess” of 1222 would get a “response” of 3-0 (3 digits in correct location, 1_22). BUT, response was 2-0, not 3-0. So remove 1322!

Eliminating Codes Could the answer be 1221? Remember the computer guessed 1222. If correct code is 1221, then a “guess” of 1222 would get a “response” of 3-0 (3 digits in correct location, 122_). BUT, response was 2-0, not 3-0. So remove 1221!

Eliminating Codes Could it be 1231? Remember the computer guessed 1222. If correct code is 1231, then a “guess” of 1222 would get a “response” of 2-0 (2 digits in correct location, 12__). Response was 2-0. So 1231 might be the right answer. Keep it!

Eliminating codes 1222 – eliminated (guessed, not correct) 1322 – eliminated (based on response) 1221 – eliminated (based on response) 1231 – still a possible answer Only 1 possible answer remaining – so it must be 1231!

How well does this strategy preform? Using a computer to simulate many Computer vs Computer gameplays, here’s how frequent each number of guesses takes: Guesses in five tries or less ~85% of the time!

Can we do better? Making an “educated guess” about which code to choose (rather than just random): Guesses in five tries or less ~97% of the time! This is what the computer program demo uses.

Can we do even better? Minimax strategy (used in economics and AI applications) can win in 5 tries or less 100% of the time. Downside: Very computationally expensive, especially when the game is extended to more digits Downside: You can get a better average number of moves when you don’t impose a hard limit of 5 moves (think about this: why might it be so?)

Good for Computers, not Humans The computer can use exhaustive search – generate all possible combinations then eliminate them Would you want to try to do exhaustive search? Computer programs have been developed that are guaranteed to solve the Mastermind problem in at most 5 guesses (and can sometimes break the code in fewer guesses).