Skip to content

Instantly share code, notes, and snippets.

@CyrusOfEden
Created November 26, 2014 00:04
Show Gist options
  • Save CyrusOfEden/f3fee66b6b26df56bb4f to your computer and use it in GitHub Desktop.
Save CyrusOfEden/f3fee66b6b26df56bb4f to your computer and use it in GitHub Desktop.
PLAYS = {
:scissors => [:paper, :lizard],
:spock => [:scissors, :rock],
:lizard => [:spock, :paper],
:rock => [:lizard, :scissors],
:paper => [:rock, :spock]
}
PLAYS.freeze
# example: rpsls(:lizard, :spock)
# returns winner as symbol, so the above would return :lizard
def rpsls(first, second)
PLAYS[first].include?(second) ? first : second
end
# alternative version, which returns true if the
# first hand beats the second one, and false otherwise
def rpsls(first, second)
PLAYS[first].include?(second)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment