In this project you will simulate all possibilities of the game and create an application that randomly generates a game and observes the outcome.
Due:
The Diffy Game is a one-player game that manipulates sequences of four whole numbers -- we will call these sequences Diffys. The game starts with an initial Diffy supplied by the user. Each move of the game replaces the current Diffy with its successor - another Diffy whose four numbers are pairwise differences of the original Diffy. For example, the successor of (2, 3, 5, 1) is (1, 2, 4, 1) because 1 is the difference of 2 and 3, 2 is the difference of 3 and 5, 4 is the difference of 5 and 1, and 1 is the difference of 1 and 2. We always take the difference by subtracting the smaller number from the larger -- another way to say this is that the difference of two numbers x and y is the absolute value of x minus y, written in C++ as abs(x-y).
If you entered a few Diffys and examined the resulting chains of Diffy successors, you may have noticed an interesting pattern: any initial Diffy will eventually lead to a Diffy consisting of four zeros. So here's the game: try to find a Diffy that will last for a long time before it zeros out. It is not too hard to find one that lasts for six turns, but what about 8, 10, or 20? Can you find any Diffys that last that long?
Develop a program that calculates the number of transformations required to reach (0, 0, 0, 0) for all four digit numbers, including those with leading zeros. Categorize each number into one of five ranges, or “bins”: 0-5, 6-10, 11-15, 16-20, and +20. The code should enable you to easily modify the range of the bins.
Your program should have the following output:
The probability of a number with between 0 and 5 transformations is XX
The probability of a number with between 6 and 10 transformations is XX
The probability of a number with between 11 and 15 transformations is XX
The probability of a number with between 16 and 20 transformations is XX
The probability of a number with more than 20 transformations is XX
To accomplish this you should write the following functions:
Your main function should cycle through all possible numbers, using the functions described above, and counting the number of transformations required to create (0, 0, 0, 0). You should then output the results.
You will find that the bins defined in step 2 do not break up the output in a particularly illustrative way. Revise the ranges so that all of the bins contain at least one Diffy number. Rename and modify the program from step 2 in order to redistribute the bins. Do not delete any changed code; simply comment it out. (Hint: Using a good programming style will minimize the number of modifications at this stage.)
In this step, you will estimate the probability that a randomly chosen number will fall within each range you specified in step three. For this program, you will not be categorizing all possible Diffy’s; rather, you will take a representative sample. The program will prompt the user for the sample size and use a random number generator to select the Diffy numbers that are part of the sample. (Do not worry about testing the same number twice in a sample.) For each Diffy number, determine the number of transformations required to produce (0, 0, 0, 0) and classify the Diffy number in the appropriate bin.
To accomplish this step, you should create the following functions:
The program will output the probability of each of the range. Experiment with different sample sizes to determine how large the sample should be to reflect the actual probabilities observed in step three.
Please email me three files, each containing a single step of the assignment.