Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # creates an array for giver:
- giver = ["Luke Skywalker luke@theforce.net",
- "Leia Skywalker leia@therebellion.org",
- "Toula Portokalos toula@manhunter.org",
- "Gus Portokalos gus@weareallfruit.net",
- "Bruce Wayne bruce@imbatman.com",
- "Virgil Brigman virgil@rigworkersunion.org",
- "Lindsey Brigman lindsey@iseealiens.net"]
- # ceates a duplicate array:
- receiver = giver.dup
- # takes the first person kicked out of the array 'givers' (Luke Skywalker) from the top
- # and assigns it to the variable 'secret santa' and removes it from the giver array
- secret_santa = giver.shift()
- # '.pop' takes the last element in the receivers array; then shuffles the rest of the elements
- selected_name = receiver.shuffle!.pop
- # makes sure the giver is not equal to the recipient then puts the first giver/receiver pair.
- if secret_santa != selected_name
- puts "#{secret_santa} is the Secret Santa of #{selected_name}"
- puts
- end
- # selects the next element in the giver array
- secret_santa2 = giver.shift()
- selected_name2 = receiver.shuffle!.pop
- # makes sure the giver is not equal to the recipient then puts the second giver/receiver pair.
- if secret_santa2 != selected_name
- puts "#{secret_santa2} is the Secret Santa of #{selected_name2}"
- puts
- end
- secret_santa3 = giver.shift()
- selected_name3 = receiver.shuffle!.pop # takes from the bottom
- if secret_santa3 != selected_name
- puts "#{secret_santa3} is the Secret Santa of #{selected_name3}"
- puts
- end
- secret_santa4 = giver.shift()
- selected_name4 = receiver.shuffle!.pop # takes from the bottom
- if secret_santa4 != selected_name
- puts "#{secret_santa4} is the Secret Santa of #{selected_name4}"
- puts
- end
- secret_santa5 = giver.shift()
- selected_name5 = receiver.shuffle!.pop # takes from the bottom
- if secret_santa5 != selected_name
- puts "#{secret_santa5} is the Secret Santa of #{selected_name5}"
- puts
- end
- secret_santa6 = giver.shift()
- selected_name6 = receiver.shuffle!.pop # takes from the bottom
- if secret_santa6 != selected_name
- puts "#{secret_santa6} is the Secret Santa of #{selected_name6}"
- puts
- end
- secret_santa7 = giver.shift()
- selected_name7 = receiver.shuffle!.pop # takes from the bottom
- if secret_santa7 != selected_name
- puts "#{secret_santa7} is the Secret Santa of #{selected_name7}"
- puts
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement