A random walk consists of a sequence of positions, each one obtained from the previous one by making a random step. In this exercise we consider random walks in the plane, starting at . Let be a strictly positive natural number. Each step will be an increment between and , random and independent, of the two coordinates.
Hence, we need a source of randomness. The usual way to simulate it consists in generating pseudorandom numbers. These numbers are the result of an algorithm, so they are not really random, but they look random enough. The linear congruential generators are defined with four natural numbers (module), (multiplier), (adder) and (initial seed). The generated sequence is
For instance, if , then we get
These numbers are between 0 and , but in this exercise we need numbers between and . The easiest way to achieve this is with the following code; use it just like that:
int random(int k, int m, int a, int b, int& s) {
s = (a*s + b)%m;
return s%(2*k + 1) - k;
}
Following with the example, for the sequence of increments is and, if we increase the first coordinate before the second one, the steps are
Write a program to compute the first steps of a sequence of random walks defined by , , , and .
Input is all natural numbers, and consists of several cases, each one in two lines. The first line contains and . The second line contains , , and . All , and are strictly positive, and , and are less than .
For each case of the input, first print its number starting at 1, followed by the walk of steps defined by , , , and . If some position gets repeated, indicate it and stop the walk as it is shown in the example. Print an empty line at the end of each case.
Input
5 2 9 2 7 3 8 1 7 2 0 5 12 100 1007 74 985 333
Output
Path #1 (0, 0) (2, -1) (1, -3) (1, -2) (3, -3) Path #2 (0, 0) (-1, -1) (0, -2) (-1, -1) repeated! Path #3 (0, 0) (-50, 95) (-41, 156) (-19, 202) (73, 102) (94, 14) (-4, -18) (-16, -102) (11, -7) (-10, 79) (51, 73) (122, 1)