Created
October 4, 2017 22:05
-
-
Save adrianobarroso/791f5163cdf5e4b53b733da469b4b878 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
sentence1 = "Oh my god" | |
sentence2 = "What the fcccc" | |
def acron(sentence) | |
result = "" | |
sentence.split(" ").each do |word| | |
result += word[0].upcase | |
end | |
return result | |
end | |
puts acron(sentence1) | |
puts acron(sentence2) |
This file contains hidden or 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
GAME_OPTIONS = ["pedra", "papel", "scissors"] | |
# index 0 1 2 | |
# => 1 - 0 = 1 w | |
# => 2 - 0 = 2 l | |
# => 2 - 1 = 1 w | |
# => 1 - 2 = -1 l | |
# => 0 - 1 = -1 l | |
# => 0 - 2 = -2 w | |
# | |
def logical_game(u_i, c_i) | |
puts "User choose #{GAME_OPTIONS[u_i]}" | |
puts "Computer choose #{GAME_OPTIONS[c_i]}" | |
diff = u_i - c_i | |
if diff == 1 || diff == -2 | |
puts "User win" | |
elsif diff == 0 | |
puts "Draw" | |
else | |
puts "User lost" | |
end | |
end | |
puts "pedra, papel ou scissors" | |
user_choice = gets.chomp | |
computer_choice = GAME_OPTIONS.sample | |
u_i = GAME_OPTIONS.index(user_choice) | |
c_i = GAME_OPTIONS.index(computer_choice) | |
logical_game(u_i, c_i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment