Created
November 26, 2014 00:04
-
-
Save CyrusOfEden/f3fee66b6b26df56bb4f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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