Last active
March 29, 2017 20:11
-
-
Save fractalatcarf/6f2acb9e76d3fd648321a466d7f6ab15 to your computer and use it in GitHub Desktop.
live code du mercredi 29 mars - acronymizer + rock_paper_scissors
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 acronymizer(sentence) | |
# séparer les mots de la phrase | |
words = sentence.split(" ") | |
# prendre la 1ere lette de chaque mot + majuscule | |
first_letters = [] | |
words.each do |word| | |
first_letters << word[0].upcase | |
end | |
# les rassembler | |
first_letters.join | |
end | |
puts acronymizer("mort de rire") # => "MDR" | |
puts acronymizer("save our souls") # => "SOS" | |
def rock_paper_scissors | |
solutions = %w(rock paper scissors) | |
human_play = nil | |
while true | |
until solutions.include?(human_play) | |
puts "Your choice (rock paper scissors)" | |
print "> " | |
human_play = gets.chomp | |
return if human_play == "" | |
end | |
machine_play = solutions.sample | |
puts machine_play | |
score = "loose" | |
score = "match null" if human_play == machine_play | |
score = "win" if solutions[solutions.index(human_play) - 1] == machine_play | |
# score = "win" if human_play == "paper" && machine_play == "rock" | |
# score = "win" if human_play == "scissors" && machine_play == "paper" | |
# score = "win" if human_play == "rock" && machine_play == "scissors" | |
puts score | |
human_play = nil | |
end | |
end | |
rock_paper_scissors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment