Gator And Ducks

Gator And Ducks

Suppose there are ducks floating on the pond in a circle. The pond is also home for alligator with a fondness for ducks. Beginning at a particular position (duck number 1) the alligator counts clockwise around the circle and eats every step-th duck (the circle closing as ducks are eaten).

For example, when ducks = 8 and step = 4, the following diagram shows duck number outside and consumption order inside:

example

The first duck is fifth on the menu, the second is forth, etc. The sequence 5, 4, 6, 1, 3, 8, 7, 2 of orders of consumption completely describes alligator's menu.

Write a script which returns the orders of consumption of the ducks given ducks, step.

Input: Two integers (int).

Output: List of integers.

Examples:

assert gator(8, 4) == [5, 4, 6, 1, 3, 8, 7, 2]
assert gator(7, 11) == [7, 2, 3, 1, 5, 6, 4]
assert gator(3, 1) == [1, 2, 3]

Precondition:

  • ducks, step > 0

The mission was taken from The International Collegiate Programming Contest - 1974.