Question: You're playing a memory game! In this game, the players take turns saying numbers. They begin by taking turns reading from a list of

You're playing a memory game! In this game, the players take turns 

You're playing a memory game! In this game, the players take turns saying numbers. They begin by taking turns reading from a list of starting numbers (your puzzle input). Then, each turn consists of considering the most recently spoken number: > If that was the first time the number has been spoken, the current player says 0. > Otherwise, the number had been spoken before; the current player announces how many turns apart the number is from when it was previously spoken. For example, suppose the starting numbers are [0,3,6]: Turn 1: The Ist number spoken is a starting number, 0. Turn 2: The 2nd number spoken is a starting number, 3. Turn 3: The 3rd number spoken is a starting number, 6. Turn 4: Now, consider the last number spoken, 6. Since that was the first time the number had been spoken, the 4th number spoken is 0. Turn 5: Next, again consider the last number spoken, 0. Since it had been spoken before, the next number to speak is the difference between the turn number when it was last spoken (the previous turn, 4) and the turn number of the time it was most recently spoken before then (turn 1). Thus, the 5th number spoken is 4 - 1, 3. Turn 6: The last number spoken, 3 had also been spoken before, most recently on turns 5 and 2. So, the 6th number spoken is 5- 2. 3. Turn 7: Since 3 was just spoken twice in a row, and the last two turns are l turn apart, the 7th number spoken is I. Turn 8: Since 1 is new, the 8th number spoken is 0. Turn 9: 0 was last spoken on turns 8 and 4, so the 9th number spoken is the difference between them, 4. Turn 10: 4 is new, so the 10th number spoken is 0. In the example above, the 2020th number spoken will be 436. Write down a program which will find the 2020th number spoken according to following starting numbers:

Step by Step Solution

3.43 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

implement the game in Java MemoryGamejava import javautilArrayList import javautilScanner public cla... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!