Q3) Another guessing game: (10 points) 1) Write a code executing the following: a) First, randomly...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Q3) Another guessing game: (10 points) 1) Write a code executing the following: a) First, randomly generate three numbers [0..9] (***The order among three numbers matters***) b) Then, continuously guess all three numbers until all three are guessed correctly. See below for two different ways of guessing three random numbers. c) Keep track of the number of guesses for the three random numbers d) Repeat the steps a) - c) x number of times in an outer loop, where x should be equal to or larger than 10,0000 e) Compute the average of guesses per try computed from x number of tries. 2) For the algorithm of guessing 3 random numbers in [0.. 9], you use two different algorithms listed below: a) Deterministic brute-force algorithm: In each try, it permutates 3 numbers in a deterministic way so that it guesses each set of 3 numbers only once while guessing the 3 random numbers. Each permutation of 3 numbers will be compared against three random numbers until they are correctly guessed. Guess the average number of guesses per try before you write your program and compare it against your simulation results. b) Pure random algorithm It will not use any prior information to guess the numbers. For each guess, it makes a fresh new guess for three new numbers randomly from scratch, and then it checks if the numbers are correct. If they are incorrect, it repeats the same process until the numbers are guessed correctly. Note that each set of guesses is completely independent. Theoretically, the upper bound of the number of guesses of this algorithm is unlimited. So, your program may stop guessing when the number of guesses reaches a certain max number (say 10,000) tries. You may record and display the number of such bailed-out cases if it happens. What would be the average number of guesses per try? Try to guess before you write your program and compare it against your simulation results. 3) This exercise may give some ideas on the difference between randomized algorithms (we will learn it later) and brute-force algorithms. Expected Output: announcements a) Deterministic brute-force guessing algorithm: Number of Tries: 10000 The highest number of guesses in a try: 998 The lowest number of tries: 3 The average number of tries: xxx.xx b) Pure random guessing algorithm Number of Tries: 10000 The highest number of guesses in a try: 8944 The lowest number of tries: 1 The average number of tries: xxX.XX Q3) Another guessing game: (10 points) 1) Write a code executing the following: a) First, randomly generate three numbers [0..9] (***The order among three numbers matters***) b) Then, continuously guess all three numbers until all three are guessed correctly. See below for two different ways of guessing three random numbers. c) Keep track of the number of guesses for the three random numbers d) Repeat the steps a) - c) x number of times in an outer loop, where x should be equal to or larger than 10,0000 e) Compute the average of guesses per try computed from x number of tries. 2) For the algorithm of guessing 3 random numbers in [0.. 9], you use two different algorithms listed below: a) Deterministic brute-force algorithm: In each try, it permutates 3 numbers in a deterministic way so that it guesses each set of 3 numbers only once while guessing the 3 random numbers. Each permutation of 3 numbers will be compared against three random numbers until they are correctly guessed. Guess the average number of guesses per try before you write your program and compare it against your simulation results. b) Pure random algorithm It will not use any prior information to guess the numbers. For each guess, it makes a fresh new guess for three new numbers randomly from scratch, and then it checks if the numbers are correct. If they are incorrect, it repeats the same process until the numbers are guessed correctly. Note that each set of guesses is completely independent. Theoretically, the upper bound of the number of guesses of this algorithm is unlimited. So, your program may stop guessing when the number of guesses reaches a certain max number (say 10,000) tries. You may record and display the number of such bailed-out cases if it happens. What would be the average number of guesses per try? Try to guess before you write your program and compare it against your simulation results. 3) This exercise may give some ideas on the difference between randomized algorithms (we will learn it later) and brute-force algorithms. Expected Output: announcements a) Deterministic brute-force guessing algorithm: Number of Tries: 10000 The highest number of guesses in a try: 998 The lowest number of tries: 3 The average number of tries: xxx.xx b) Pure random guessing algorithm Number of Tries: 10000 The highest number of guesses in a try: 8944 The lowest number of tries: 1 The average number of tries: xxX.XX
Expert Answer:
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
"internet radios" for streaming audio, and personal video recorders and players. Describe design and evaluation processes that could be used by a start-up company to improve the usability of such...
-
The new line character is utilized solely as the last person in each message. On association with the server, a client can possibly (I) question the situation with a client by sending the client's...
-
1. Find the perimeter of each figure. 2. 52 feet 40 feet 52 feet 72 feet 11 kilometers 20 kilometers 35 kilometers
-
KS Media Corporation had the following income statement and balance sheet for 2017: Compute the following for KS during 2017: a. Acquisition of equipment. KS sold no equipment during the year. b....
-
How has the target audience for IBM's products and services evolved over time? How have the types of business problems that IBM addresses in their advertising changed?
-
Petitioner Salman was indicted for federal securities-fraud crimes for trading on inside information he received from a friend and relative-by-marriage, Michael Kara, who, in turn, had received the...
-
IBS is a global provider of point-of-sale systems and related services that enable businesses to accept electronic payments. As a new hire in the companys international headquarters accounting...
-
Two identical loudspeakers are driven in phase by a common oscillator at 880 Hz and face each other at a distance of 1.22 m. Locate the points along the line joining the two speakers where relative...
-
The case study shown below provides an overview of Road Transit Systems (RTS) - a specialist preventative vehicle maintenance program operator in NSW, Australia. A number of attributes have been...
-
Which of the following statements about carrier proteins is FALSE? They can become saturated if the maximum transport rate is exceeded. They assist in simple diffusion. They might have to change...
-
What are the five most important managerial skills/characteristics in today's organizations for managers to be successful, and why did you select those as your top five? What managerial theory or...
-
How does cloud computing potentially impact the planning of (either internal or external) audit?
-
Explain the control areas that an IT auditor should focus on when evaluating an AIS.
-
2. The article mentions that performance measurement (including the balance scorecard) works on the premise of "What you measure is what you get". What does this mean and where else have you seen...
-
Kaneohe Canned Meats needs to replace an old piece of equipment and is conducting a lease or sell differential analysis. Costs of leasing the machine to a third party are: Estimated Repair Expense...
-
An electronics firm produces electronic equipment, which it supplies to various electrical manufacturers. Quality control records indicate that different employees produce different numbers of...
-
(8%) Problem 6: A student attaches a f= 3.5 kHz oscillator to one end of a metal rail of length L = 25 m. The student turns on the oscillator and uses a piezoelectric gauge at the other end to...
-
What does the following app do? // Exercise 6.10 Solution: Printing.cs using System; class Printing { static void Main() 6 { for (int i - 1; i
-
Create the GUI in Fig. 14.1 (you do not have to provide functionality). Figure 14.1 Calculator GUI 4 1 9, 6. 3. 2.
-
State whether each of the following is true or false. If false, explain why. a) Functional programmings filter, map and reduce operations correspond to the IEnumerable extension methods Where, Select...
-
Graph the following table: a. What is marginal product and average product at each level of production? b. Graph marginal product and average product. c. Label the areas of increasing marginal...
-
If average product is falling, what is happening to short-run average variable cost?
-
If marginal cost is increasing, what do we know about average cost?
Study smarter with the SolutionInn App