[Tutor] Rock, Paper, Scissors game

Saad Javed sbjaved at gmail.com
Fri Jul 26 21:59:12 CEST 2013


> I would never have come up with this line, but I think it can be pictured as
> follows:
>
> Given the cycle
>
> +-->rock-->paper-->scissors--+
> |                            |
> +---------------<------------+
>
> and only one direction allowed the winning "weapon" is always the one
> farther away from the loser, e. g.
>
> rock vs paper
> rock-->paper: 1 step
> paper-->scissors-->rock: 2 steps
> paper wins
>
> rock vs rock:
> 0 steps both
> tie
>
> The modulo operator helps with determining this "directed distance" by
> maintaining
>
> -n == N-n
>
> e. g.
>
> -1 % 3 == 3 - 1 == 2
>
> You could anecdotally test the above outline by adding more weapons. For
> four weapons you should get ties between distinct weapons:
>
> +-->rock-->paper-->scissors-->banana--+
> |                                     |
> +---------------<---------------------+
>
> rock vs scissors:
> rock-->paper-->scissors: 2 steps
> scissors-->banana-->rock: 2 steps
> tie
>
> You can modify the script to work with an arbitrary number of weapons by
> replacing 3 with length(weapons) if you like.

Thank you for taking out the time to explain.


More information about the Tutor mailing list