Information about 4 Digit Number Guessing Game

Watch

• Bulls and Cows1 • Strategy2 • Cheating3

Bulls and Cows

Bulls and Cows 1. an old code-breaking paper and pencil game for two players 2. the players each write a 4-digit secret number 3. Moo

Rule 1. Players take turns to guess each other’s secret number. 2. For each guess, players respond “bulls” and “cows” for correct digit and orders.

Demo 数当てゲームMOOの最小質問戦略と 最強戦略

C Programming Homework #2 1. Generate a secret 4-digit number: – Random numbers between 0~9 without repetition 2. Compare your guess with the secret number: – Output *A*B

rand function int i = 0; while(i < 10) { printf("%dn", rand()); i++; }

srand function int i = 0; srand(12); while(i < 10) { printf("%dn", rand()); i++; }

time function #include <time.h> int i = 0; srand(time(NULL)); while(i < 10) { printf("%dn", rand()); i++; }

Array my_Guess com_Ans

Calculate ? A for (i=0; i<4; i++) { if (my_Guess[i]==com_Ans[i]) { a_Count++; } }

Calculate ? B for (i=0; i<4; i++) { if (my_Guess[i]!=com_Ans[i]) { for (j=0; j<4; j++) { if (i!=j && my_Guess[i]==com_Ans[j]) { b_Count++; } } } }

Combination 5040 Possibilities 14 Categories

Logic Tree 応答は 4A, 3A, 2A2B, 2A1B, 2A, 1A3B, 1A2B, 1A1B, 1A, 4B, 3B, 2B, 1B, 0A0B の14種

2 Strategy Stylize, edit, and animate your media

Question 1. Is there an algorithm that can identify what guesses should be made? 2. What is the best strategy?

Research One giving an optimal strategy requiring an average number of guesses of 4.34, with a maximum of 6 is given by Koyama and Lai in 1993. A slight modification, reduces the maximum number of guesses to 5, but increases the average to 4.341. 数当てゲームMOOの最小 質問戦略と最強戦略

Approach (1) Random Method: – Blind Random – Human Instinct

Example: Blind Random

Approach (2) Improved Progress: Ø Eliminate Impossible

Eliminate Impossible 1234 3A0B 24 1235 1236 1237… 1534 1634 1734… 5234 6234 7234… 3456 7890 1357… 6890 9781 2579… 4567 1568 8312… ……………………………

Approach(3) Fixed Algorithm: – Smallest Number – Frequency of Occurrence – Weight Based Method

Example: Smallest Number 1234 3A0B 24 1235 1236 1237… 1534 1634 1734… 5234 6234 7234…

Example: Frequency of Occurrence How many times each digit occurs in the list of possible solutions? Possible Results: 782、876、951、436 0 1 2 3 4 5 6 7 8 9 0 1 2 1 1 1 2 2 2 1 782 2+2+1 = 5 876 2+2+2 = 6 951 1+1+1 = 3 436 1+1+2 = 4

Weight Based Method 0 1 2 3 4 5 6 7 8 9 Provide each number a weightage based on the bulls and cows that the number has generated

Computer Vs. Human

Human Thinking 1234 0A0B 5678 0A3B 6789 2A2B 7689 ------- 6987 ------- 8769 -------

Human Thinking 1234 0A2B 5678 0A1B 9032 0A2B 3724 0A1B 9321 1A2B New Guess: 9613

Computer Thinking 1023 1024 1025… 2013 2014 2015… 3012 3014 3015… 4012 4013 4015… 5012 5013 5014… …………………………… ……………………………

Cheating Design, organize, and collaborate

Change Result Predefined Result: ‘1203’ Change to other possible result Ex.’1863’

Give the Worst Response 1B 1440 2B 1260 1A1B 720 1A0B 480 ……..

Logic Tree 応答は 4A, 3A, 2A2B, 2A1B, 2A, 1A3B, 1A2B, 1A1B, 1A, 4B, 3B, 2B, 1B, 0A0B の14種

Escape to the Crowds 681、724、539、137 Player Guess ‘123’ Respond “0A1B”

Find YOUR Method

DEMO

C PROGRAM

C Program Design

main function int main () { Secret(); Guess(); Compare(); return 0; }

Function Design

Secret function void Secret() { srand ( time(NULL) ); ... ... ... ... }

Guess function void Guess(){ printf("nPlease Input Your Guess:"); scanf("%i", &my_Guess_Temp); my_Guess[0] = ...; my_Guess[1] = ...; my_Guess[2] = ...; my_Guess[3] = ...; }

Compare function void Compare(){ a_Count=0; b_Count=0; for (i=0; i<4; i++) { if (my_Guess[i]==com_Ans[i]) { a_Count=a_Count++; }} .........

C Program Design

Function Design

Total Answer Database

int answerBase[5040][4]; For(i=0; i<10000; i++) ………………………………………

Check Anwer with Guess 1023 1024 1025… 2013 2014 2015… 3012 3014 3015… 4012 4013 4015… 5012 5013 5014… …………………………… ……………………………

For(i=0; i<5040; i++) If (answerBase[i][0] == 1) (answerBase[i][1] == 2) (answerBase[i][2] == 3) (answerBase[i][3] == 4) ………………………………………3 A 0 B 3A0B

Eliminate Impossible Answer from Database 1234 3A0B 24 1235 1236 1237… 1534 1634 1734… 5234 6234 7234… 3456 7890 1357… 6890 9781 2579… 4567 1568 8312… ……………………………

MIDTERM PROJECT

Content of Report 1. 遊戲獲勝的策略和方法 2. 遊戲畫面的設計圖 3. 其它增加遊戲的樂趣的新創意?

New Idea

If at first, the idea is not absurd, then there is no hope for it. Albert Einsten

Delivers 1. C Programming Code 2. Design Report

Design Report Strategy Description App Visual Design < 3 Pages

Design an Mobile App

Visual Sketch

Midterm Project Design Report Contest C code

Midterm Project: 4/25 3 students design 1 C program

Teamwork 分工合作： • 3個⼈的Project, 最後只有一個人在做事。 • 何謂負責？ • Team Members：溝通、互相鼓舞

C Programming is Easy! aragornyeh@gmail .com

Description Who could think that guessing a 4 digit number would be so difficult? Well, in 4 Digits, you may find out that it is in fact one of ...

Read more

Who could think that guessing a 4 digit number would be so difficult? Well, in 4 Digits, you may find out that it is in fact one of the most challenging ...

Read more

4 digit 7 segment number guessing game ... Controlling a 7 Segment 4 Digit Display with the Arduino ... Number Guessing Game ...

Read more

Who could think that guessing a 4 digit number would be so difficult? Well, in 4 Digits, you may find out that it is in fact one of the most challenging ...

Read more

As this part of the question has been skipped so far, I'll take it: Do you think this is too hard? I think it is. Similarly to your game, in classic ...

Read more

Consider the following number-guessing game: Player A thinks of a 4-digit secret integer between the range of 1000 and 9999, inclusive. Player B formulates ...

Read more

I am having trouble with a program I'm writing. It is supposed to be a kind of guessing game. the program will create a random 4 digit number with digits ...

Read more

Number Guessing. In this simple game, ... have 1 in the 3rd position (4, 5, 6, 7 ... to realize that the 3rd digit of your number is 1 ...

Read more

I'm designing a Number Guessing Game, that reads a 4 Digit number from the Console. The computer randomly generates the 4 digit number and the user tries ...

Read more

Introduction. This article will give you some tips to write a simple "Random Number Guessing Game" using C#. The program generates a 4 digit ...

Read more

## Add a comment