Back to front pageView on Hacker News (opens in a new tab)Ask HN: What's your favorite elegant/beautiful algorithm?733 pointsby algobuddy (on Hacker News)8 years agoComments (491) 209 threadsShow all commentsShowing thread 152 of 209busterarm8 years ago#Rock, Scissors, Paper in a circular array.All you have to do to test for win condition is check if the other player has the next item in the array.Equality is a tie.Base case is a loss.It's also my favorite case of structuring data in a way that makes the algorithm self-evident.
Ask HN: What's your favorite elegant/beautiful algorithm?733 pointsby algobuddy (on Hacker News)8 years ago
busterarm8 years ago#Rock, Scissors, Paper in a circular array.All you have to do to test for win condition is check if the other player has the next item in the array.Equality is a tie.Base case is a loss.It's also my favorite case of structuring data in a way that makes the algorithm self-evident.
Comments (491) 209 threads
Show all comments
Showing thread 152 of 209
All you have to do to test for win condition is check if the other player has the next item in the array.
Equality is a tie.
Base case is a loss.
It's also my favorite case of structuring data in a way that makes the algorithm self-evident.