6 kyu

Simple Fun #345: The Original Numbers

53 of 61myjinxin2015

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 ^_^

Puzzles
Games
Mathematics

Stats:

CreatedSep 18, 2017
PublishedSep 18, 2017
Warriors Trained222
Total Skips38
Total Code Submissions196
Total Times Completed61
JavaScript Completions53
Python Completions11
Total Stars4
% of votes with a positive feedback rating94% of 24
Total "Very Satisfied" Votes22
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • docgunthrop Avatar
  • saudiGuy Avatar
Ad