6 kyu

Simple Fun #58: Volleyball Positions

126 of 278myjinxin2015

Description:

Task

You are watching a volleyball tournament, but you missed the beginning of the very first game of your favorite team. Now you're curious about how the coach arranged the players on the field at the start of the game.

The team you favor plays in the following formation:

0 3 0
4 0 2
0 6 0
5 0 1

where positive numbers represent positions occupied by players. After the team gains the serve, its members rotate one position in a clockwise direction, so the player in position 2 moves to position 1, the player in position 3 moves to position 2, and so on, with the player in position 1 moving to position 6.

Here's how the players change their positions:

Given the current formation of the team and the number of times k it gained the serve, find the initial position of each player in it.

Example

For

formation = [["empty",   "Player5", "empty"],
             ["Player4", "empty",   "Player2"],
             ["empty",   "Player3", "empty"],
             ["Player6", "empty",   "Player1"]]
and k = 2

the output should be

[
    ["empty",   "Player1", "empty"],
    ["Player2", "empty",   "Player3"],
    ["empty",   "Player4", "empty"],
    ["Player5", "empty",   "Player6"]
]

For

formation = [["empty", "Alice", "empty"],
             ["Bob",   "empty", "Charlie"],
             ["empty", "Dave",  "empty"],
             ["Eve",   "empty", "Frank"]]
and k = 6

the output should be

  [
    ["empty", "Alice", "empty"],
    ["Bob",   "empty", "Charlie"],
    ["empty", "Dave",  "empty"],
    ["Eve",   "empty", "Frank"]
]

Input

  • 2D string array formation

    A 4 × 3 array of strings representing names of the players in the positions corresponding to those in the schema above.

    It is guaranteed that for each empty position the corresponding element of formation is "empty".

    It is also guaranteed that there is no player called "empty" in the team.

  • Integer k

    The number of times the team gained the serve.

    Constraints: 0 ≤ k ≤ 1000000000.

Output

  • 2D string array

    Team arrangement at the start of the game.

Puzzles

Stats:

CreatedJan 26, 2017
PublishedJan 26, 2017
Warriors Trained749
Total Skips82
Total Code Submissions879
Total Times Completed278
JavaScript Completions102
C# Completions59
Python Completions126
Ruby Completions21
Total Stars18
% of votes with a positive feedback rating94% of 81
Total "Very Satisfied" Votes73
Total "Somewhat Satisfied" Votes7
Total "Not Satisfied" Votes1
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • hobovsky Avatar
  • dfhwze Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad