Advertisement
Guest User

Untitled

a guest
Jun 17th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. # # Choose a Secret Santa for every name in the list. Obviously, a person cannot be their own Secret Santa.
  2. # #
  3. # # Output is obvious. Print out each person's secret Santa.
  4. #create 2 separate arrays because no method can be called from just one
  5.  
  6. gifters = ["Luke Skywalker luke@theforce.net",
  7. "Leia Skywalker leia@therebellion.org",
  8. "Toula Portokalos toula@manhunter.org",
  9. "Gus Portokalos gus@weareallfruit.net",
  10. "Bruce Wayne bruce@imbatman.com",
  11. "Virgil Brigman virgil@rigworkersunion.org",
  12. "Lindsey Brigman lindsey@iseealiens.net"]
  13.  
  14. takers = ["Luke Skywalker luke@theforce.net",
  15. "Leia Skywalker leia@therebellion.org",
  16. "Toula Portokalos toula@manhunter.org",
  17. "Gus Portokalos gus@weareallfruit.net",
  18. "Bruce Wayne bruce@imbatman.com",
  19. "Virgil Brigman virgil@rigworkersunion.org",
  20. "Lindsey Brigman lindsey@iseealiens.net"]
  21.  
  22.  
  23. #shift on this will return the first element of Luke and remove it from the array
  24. gift_buyer = gifters.shift()
  25.  
  26. #assigning a different variable
  27. #utilizing .pop will take the last element and remove it from the array
  28. #.shuffle method will mix up the rest
  29.  
  30. name_drawn = takers.shuffle!.pop
  31.  
  32. # calling out the method above to output a specific action - long way
  33.  
  34. if gift_buyer != name_drawn
  35. puts "#{gift_buyer} is #{name_drawn}'s secret santa"
  36. end
  37.  
  38. # each if/else statement has an 'end' so i have to call a method on each if/else line
  39.  
  40. gift_buyer2 = gifters.shift()
  41. name_drawn2 = takers.shuffle!.pop
  42. if gift_buyer2 != name_drawn2
  43. puts "#{gift_buyer2} is #{name_drawn2}'s secret santa"
  44. end
  45.  
  46. gift_buyer3 = gifters.shift()
  47. name_drawn3 = takers.shuffle!.pop
  48. if gift_buyer3 != name_drawn3
  49. puts "#{gift_buyer3} is #{name_drawn3}'s secret santa"
  50. end
  51.  
  52. gift_buyer4 = gifters.shift()
  53. name_drawn4 = takers.shuffle!.pop
  54. if gift_buyer4 != name_drawn4
  55. puts "#{gift_buyer4} is #{name_drawn4}'s secret santa"
  56. end
  57.  
  58. gift_buyer5 = gifters.shift()
  59. name_drawn5 = takers.shuffle!.pop
  60. if gift_buyer5 != name_drawn5
  61. puts "#{gift_buyer5} is #{name_drawn5}'s secret santa"
  62. end
  63.  
  64. gift_buyer6 = gifters.shift()
  65. name_drawn6 = takers.shuffle!.pop
  66. if gift_buyer6 != name_drawn6
  67. puts "#{gift_buyer6} is #{name_drawn6}'s secret santa"
  68. end
  69.  
  70. gift_buyer7 = gifters.shift()
  71. name_drawn7 = takers.shuffle!.pop
  72. if gift_buyer7 != name_drawn7
  73. puts "#{gift_buyer7} is #{name_drawn7}'s secret santa"
  74. end
  75.  
  76. # ??? I think a loop can be created or a class, which is where I got stuck :(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement