The game is implemented in various languages, including PHP Ruby and Python and most seem to be structured as:
- create a randomized list of numbers
- while the list is not sorted:
- ask for and input the number to be reversed
- reverse that portion of the list.
Here is proof for Python:
If you were testing an implementation or otherwise running it, every once in a while it would just exit. Run it again and it would most likely work for a long time. It is not something I would like to use the normal xUnit type tests/continuous testing regime to uncover as although a transient fail would be noted, those test regimes rely heavily on easy reproducibility of the failure.
>>> n = 10
>>> sortlist = range(n)
>>> randlist = range(n)
>>> random.shuffle(randlist)
>>> x = 0
>>> while randlist != sortlist:
... x += 1
... random.shuffle(randlist)
...
>>> print x
714418
>>>
I guess what would be needed is knowledge of corner cases. For shuffle, corner cases to think of would include returning the input order, reverse input order, sorted, and reverse sorted order.
- Paddy.
P.S. Work pays me to be this finickity when testing ASICs