Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement