hoodwink.d enhanced

Fri Dec 16

Despite all the mess and the broken glass I was impressed.

Andrew Bird in The Naming of Things

private message

09:30 <sam-> i posted the secret santa thing on projectionist
09:30 <noradio> i GNU/know, i GNU/saw
09:30 <sam-> but have you GNU/hurd?

Ruby Secret Santa

class Array def shuffle! replace sort_by { rand } end end class SecretSanta include Enumerable def initialize(people) @from, @to = people.dup.shuffle!, people.dup assign! end def assign! @to.shuffle! until no_two_indices_are_alike end def each(&block) @from.zip(@to).each &block end private def no_two_indices_are_alike all? { |a, b| a != b } end end s = SecretSanta.new(Person.find(:all)) # Print Secret Santa pairings pp Hash[*s.to_a.flatten.map {|person| person.name}]