Skip to content

Instantly share code, notes, and snippets.

@adrianobarroso
Created October 4, 2017 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianobarroso/791f5163cdf5e4b53b733da469b4b878 to your computer and use it in GitHub Desktop.
Save adrianobarroso/791f5163cdf5e4b53b733da469b4b878 to your computer and use it in GitHub Desktop.
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)
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