On Mon, 4 Oct 2004 07:19:57 +0900
James Edward Gray II <james / grayproductions.net> wrote:

| On Oct 3, 2004, at 8:04 AM, Thomas Leitner wrote:
| 
| > And here is my version of the second quiz. It does not use
| > 'net/smtp' but shows the chosen santas on the console.
| >
| > Thomas
| 
| Did you run this program on the provided test data?
| 
| I believe it has the same catch in it I posted about in Robo's code 
| earlier today, though it displays it differently.  If I run it 10 or
| 20 times, it eventually hangs on me.
| 
| James Edward Gray II
| 
| 
| 

Yes, I did this. I have run the program 10000 times now and it never hung on me or produced false answers. I'm using

[penguin 42] ~ > ruby -v
ruby 1.8.1 (2004-04-24) [i686-linux-gnu]

Hmm, I just configured my system to use ruby 1.9

[penguin 110] ~ > ruby -v
ruby 1.9.0 (2004-08-03) [i686-linux]

and now it also began to hang...

.... busy working ...

So, after having this message open in my editor for too long now, it "seems" I have found the problem. I changed the lines 

def choose_santas( list )
  list.each do |person, possible_santas|
    begin santa = possible_santas[rand( possible_santas.length )] end until verify_santa( list, person, santa )
    list.each_value { |value| value.delete( santa ) if Array === value }
    list[person] = santa
  end
end

to this 

def choose_santas( list )
  list.each do |person, possible_santas|
    begin
      santa = possible_santas[rand( possible_santas.length )]
    end until verify_santa( list, person, santa )
    list.each_value { |value| value.delete( santa ) if Array === value }
    list[person] = santa
  end
end

(the 'begin' ... 'end until' statements are on separate lines) and now the program also runs 10000 times :-)

Bad thing about it: I don't really know why it works now :-(

Thomas