Skip to content

Instantly share code, notes, and snippets.

@cored
Created March 5, 2012 23:43
Show Gist options
  • Save cored/1982120 to your computer and use it in GitHub Desktop.
Save cored/1982120 to your computer and use it in GitHub Desktop.
class WrongNumberOfPlayersError < StandardError ; end
class NoSuchStrategyError < StandardError ; end
module Lee
def self.palindrome?(str)
word = str.split(/\W+/).join("").downcase
str = word
word == str.reverse
end
def self.count_words(str)
str.downcase.split(/\W+/).reduce({}) do |result, element|
result[element] = result.has_key?(element) ? result[element] + 1 : 1
result
end
end
def self.rps_game_winner(game)
raise WrongNumberOfPlayersError unless game.size == 2
winner = []
game.each_with_index do |item, idx|
raise NoSuchStrategyError unless item[1] =~ /P|S|R/
if item[1] == 'S' && game[idx+1][1] == 'P'
winner = item
end
end
winner
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment