Simple Fun #345: The Original Numbers
Description:
Task
Some players are playing a game: They stand in a circle, and each player has a card with the number on it. They put the card in front of their chest. That is to say, each player can see the numbers of other players, but can't see his own.
In each turn, each player adds up the numbers he sees and writes it to the new card. For example:
There are 3 players: A,B and C
The original numbers of A,B,C is 1,0,4
Let's see the next 4 turns:
Player: A B C
turn 0: 1 0 4
turn 1: 4 5 1 // A:0+4;B:1+4;C:1+0
turn 2: 6 5 9 // A:5+1;B:4+1;C:4+5
turn 3: 14 15 11 // A:5+9;B:6+9;C:6+5
turn 4: 26 25 29 // A:15+11;B:14+11;C:14+15
Hmm.. Your task is coming: Now, suppose you don't know the original numbers. You are given the final numbers
(an array) and turns
(a positive integer), can you get the original numbers?
Examples
For finalNumbers = [26,25,29] and turns = 4
. The output should be [1,0,4]
.
The validation process can be referred to the above example.
For finalNumbers = [1248,1226,1204,1182] and turns = 3
. The output should be [12,34,56,78]
.
The validation process:
Player: A B C D
turn 0: 12 34 56 78
turn 1: 168 146 124 102
turn 2: 372 394 416 438
turn 3: 1248 1226 1204 1182
Note
All inputs are valid.
The order of numbers must be correct.
Happy Coding
^_^
Similar Kata:
Stats:
Created | Sep 18, 2017 |
Published | Sep 18, 2017 |
Warriors Trained | 222 |
Total Skips | 38 |
Total Code Submissions | 196 |
Total Times Completed | 61 |
JavaScript Completions | 53 |
Python Completions | 11 |
Total Stars | 4 |
% of votes with a positive feedback rating | 94% of 24 |
Total "Very Satisfied" Votes | 22 |
Total "Somewhat Satisfied" Votes | 1 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |