I finally got the code to work (it's on github).
So let me explain a few things of what it does. It's not the most efficient thing in the world (log linear), but it works.
1. There's a sorter in here that organizes the lists by last name. I don't remember why I put it in here, but once I can figure out how the code works without it, I'll remove it.
2. Each person gets randomly set to a gift person. As long as it's not a family person (as goes the Ruby Quiz rules), it deletes that person out of the gift array.
3. If the last person ends up with himself, the whole process is restarted.
Occasionally I get errors:
secretsanta.rb:51:in `+': can't convert nil into String (TypeError)
Not sure how to go about fixing that yet, so if I can't figure it out tomorrow, I'll send it over to stackoverflow. The error only comes up less than 1% of the time when using 100 random names, so it can't be too big of a deal.
Goodnight, rubyers! Hopefully I can go back and solve the rock paper scissors game tomorrow; if not, I'll find another rubyquiz hack to work on.
No comments:
Post a Comment