Write a programExercise 4/4Intermediate30 XP

Hot potato

Task

Children stand in a circle passing a hot potato. The program reads the children's names (one line, separated by spaces) and a number k on the next line. Counting starts at the first name: 1, 2, …, k - the child where the counting ends leaves the circle. The next count starts at the child who stood after them. The program prints the names in the order they left, each on its own line.

For the names Ada Ben Cyril Dana Emil and k = 2 they leave in this order: Ben, Dana, Ada, Emil and Cyril.

A queue helps: collections.deque with the append and popleft methods (or rotate).

Examples

  • Input

    Ada Ben Cyril Dana Emil
    2

    Expected output

    Ben
    Dana
    Ada
    Emil
    Cyril

After you submit, 4 hidden tests will also check your solution: k = 1, k = 3, one child, seven children.

Python starts the first time you run code.

Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.

Input (stdin)

Each line = one call to input().

Output

Hints

Try it yourself first. Each hint reveals a little more - and lowers the reward a little.

Signed out, hints are free - but no XP is awarded either.

Solution

The solution unlocks after the last hint.