Skip to content

Instantly share code, notes, and snippets.

@nielsdoorn
Created December 16, 2014 09:01
Show Gist options
  • Save nielsdoorn/9da6e134fe75f793485d to your computer and use it in GitHub Desktop.
Save nielsdoorn/9da6e134fe75f793485d to your computer and use it in GitHub Desktop.
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