Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. def acronymizer(sentence)
  2. # séparer les mots de la phrase
  3. words = sentence.split(" ")
  4.  
  5. # prendre la 1ere lette de chaque mot + majuscule
  6. first_letters = []
  7. words.each do |word|
  8. first_letters << word[0].upcase
  9. end
  10.  
  11. # les rassembler
  12. first_letters.join
  13.  
  14. end
  15.  
  16. puts acronymizer("mort de rire") # => "MDR"
  17. puts acronymizer("save our souls") # => "SOS"
  18.  
  19. def rock_paper_scissors
  20. solutions = %w(rock paper scissors)
  21. human_play = nil
  22.  
  23. while true
  24. until solutions.include?(human_play)
  25. puts "Your choice (rock paper scissors)"
  26. print "> "
  27. human_play = gets.chomp
  28. return if human_play == ""
  29. end
  30.  
  31. machine_play = solutions.sample
  32. puts machine_play
  33.  
  34. score = "loose"
  35. score = "match null" if human_play == machine_play
  36. score = "win" if solutions[solutions.index(human_play) - 1] == machine_play
  37. # score = "win" if human_play == "paper" && machine_play == "rock"
  38. # score = "win" if human_play == "scissors" && machine_play == "paper"
  39. # score = "win" if human_play == "rock" && machine_play == "scissors"
  40.  
  41. puts score
  42.  
  43. human_play = nil
  44. end
  45.  
  46. end
  47.  
  48. rock_paper_scissors
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement