Created
December 16, 2014 09:01
-
-
Save nielsdoorn/9da6e134fe75f793485d 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
def do_i_win my_choice, your_choice | |
if my_choice == 'rock' and your_choice == 'scissors' | |
return true | |
elsif my_choice == 'paper' and your_choice == 'rock' | |
return true | |
elsif my_choice == 'scissors' and your_choice == 'paper' | |
return true | |
end | |
return false | |
end | |
choices = ['rock','paper','scissors'] | |
my_choice = choices.sample | |
puts "type 1 for rock, 2 for paper or 3 for scissors" | |
your_choice = choices[gets.chomp.to_i-1] | |
puts "I had #{my_choice} and you had #{your_choice}" | |
if do_i_win my_choice, your_choice | |
puts 'I win' | |
elsif do_i_win your_choice, my_choice | |
puts 'You win' | |
else | |
puts 'Draw' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment