October 09, 2016

Pulsing sequence generator

Imagine you need to generate "pulsing" sequence of numbers, which should continuously repeat while going up and down between needed values, like this: 5-6-7-8-9-10-9-8-7-6-5-6-7...
Purposes of such sequence may be different, but anyway, we want to have universal solution even for this simple problem. Algorithm is simple too...
You can test this algorithm onlie on IDEone. Source code available on GitHub. Moreover, you can try to play with it using online plotter.