--------------040703040306080602010409
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Here's my first attempt to a ruby quiz :)

I take a look at what is happening here all weeks since a certain amount 
of time now but have never posted a solution. First I'd like to say that 
I found the last week's quiz very interesting even if there was only a 
small participation. I wish I could have sent a solution but I didn't 
have the time for this.

So, back to this week's quiz, my solution is simply a breadth-first tree 
walk. I believe there may be a simplier way to solve this but that's 
what I came with and it works. So I'm really happy with it :)
However, even with the code part, I think it could be more rubyist, and 
so, prettier to read. Any comments on it are welcome.

Thanks a lot for this quiz. I'm waiting for the other's solution and of 
course for the next quiz.

Ghislain

--------------040703040306080602010409
Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0";
 nameubyquiz"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filenameubyquiz"

IyEvdXNyL2Jpbi9lbnYgcnVieQojIC0qLSBjb2Rpbmc6IFVURi04IC0qLQoKCiMgQSBQb3Np
dGlvbiBvbiB0aGUgY2hlc3MgYm9hcmQuIENhbiBiZSBjaGVja2VkIGlmIHZhbGlkIHVzaW5n
IHRoZQojIFBvc2l0aW9uI3ZhbGlkPyBtZXRob2QuCmNsYXNzIFBvc2l0aW9uIDwgU3RyaW5n
CgogICAjIENyZWF0ZSBhIG5ldyBwb3NpdGlvbi4gRGVmYXVsdCB0byAnYTEnLgogICBkZWYg
aW5pdGlhbGl6ZSh2YWx1ZSA9ICdhMScpCiAgICAgIHN1cGVyKHZhbHVlKQogICBlbmQKCiAg
ICMgQ2hlY2sgd2hldGhlciB0aGUgUG9zaXRpb24gaWYgdmFsaWQgKGJldHdlZW4gJ2ExJyB0
byAnaDgnKS4KICAgZGVmIHZhbGlkPwogICAgICBzZWxmID1+IC9bYS1oXVsxLThdLwogICBl
bmQKCiAgICMgQXBwbHkgYSBtb3ZlIHRvIGEgUG9zaXRpb24sIHJldHVybmluZyBhIG5ldyBQ
b3NpdGlvbi4KICAgZGVmIGNoYW5nZShtb3ZlKQogICAgICB2YWx1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