Simulating the algorithm.