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
-
Q1. You have identified a market opportunity for home media players that would cater for older members of the population. Many older people have difficulty in understanding the operating principles...
-
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
-
Use the Techno Toys Ltd. data in Starter 17-9 to compute the following: a. New borrowing or payment of long-term note payable, with Techno having only one long-term note payable transaction during...
-
To what extent has modern science and the use of reason displaced religion in the modern world? Is religion compatible with science and rationality?
-
Figure 20.24 shows the flowsheet for a process for the production of methanol from synthesis gas (a mixture of hydrogen, carbon monoxide, and carbon dioxide and a small quantity of residual methane,...
-
Avanti manufactures embroidered jackets. The company prepares flexible budgets and uses a standard cost system to control manufacturing costs. The following standard unit cost of a jacket is based on...
-
Write a Go program that processes a list of messages using a concurrent function. A main function passes the list of messages to a go function that encrypts each message and send each resulting...
-
When coal is burned to form synthesis gas (syngas), which contains mostly CO, H 2 , H 2 S, and CO 2 , the H 2 S must be removed. The gas is called syngas because H 2 and CO are the building blocks...
-
Let assume the current temperature of the cosmic microwave background radiation is 2.9 K. [10 points) a). What is the energy-flux? b). What is the peak-wavelength of the CMB today? a What was the...
-
Casper Inc. issued shares of $1,000,000 in the current accounting period. How will this transaction affect the cash flow statement, if Casper uses the indirect method of calculating the cash flow?
-
What is the major reason for the Profitability of the wireless communications services industry tends to be low throughout the world. ?
-
Eastman Service Enterprises bills Trait Company for janitorial services rendered. Eastman's journal entry to record the collection of the account will include a credit to Owner's Capital. Service...
-
A federal tax law enacted in 2017 did what with respect to the Affordable Care Act's individual mandate?
-
Assume you are preparing an indirect cash flow statement. Please identify the section (Activities) of the cash flow statement and whether the change represents a source or a use of cash.
-
Data for CW Corporation (for the year 2021): Marketable Securities = PHP 100,000, Net Fixed Assets = PHP 2,000,000, Long-term Debt = PHP 1,000,000, Common Stock = PHP 100,000, Retained Earnings = PHP...
-
Consider the sections of two circuits illustrated above. Select True or False for all statements.After connecting a and b to a battery, the voltage across R1 always equals the voltage across R2.Rcd...
-
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...
-
__________ is the special systems test that determines the time duration to process transaction data. (a) Peak load testing (b) Performance time testing (c) Unit testing (d) Recovery testing
-
The testing technique that requires devising test cases to exercise the internal logic of a software module is called ___________. (a) Black box testing (b) Special systems testing (c) Glass box...
-
From where test data (to test the system) are made available? (a) Live environment (b) Test libraries (c) Dummy data (d) All of these
Study smarter with the SolutionInn App