From: "Hal E. Fulton" Date: 2002-08-08T14:40:42+09:00 Subject: Re: A very small challenge ----- Original Message ----- From: "Dave Thomas" To: "ruby-talk ML" Sent: Wednesday, August 07, 2002 10:19 PM Subject: Re: A very small challenge > I've played with the idea of recording the winner in a Round > object. It seems fairly natural: (some snips) > # return the better of this card and another > def best_of(other) > if @suit == other.suit > @rank > other.rank ? self : other > elsif other.suit == :spade > other > else > self > end > end > end Yes! Thank you. You've made a simplification here which is tricky enough that I'll point it out. You may even have done it semi- unconsciously. :) I was thinking in terms of a "comparison" -- compare the value of this card with that one. But you'd need to know what suit led. So I had confused myself. Not uncommon. In a simple comparison, x and y have a relationship that's fixed without regard to ordering. I'm not making sense, am I? :) But as long as you compare the cards in order from *earliest* to *latest*, you don't worry what suit led. Why this might be considered odd can be seen by looking at these two cases: D6.best_of(C8) # C8 C8.best_of(D6) # D6 - different answers In other words, the chronologically earlier one wins. Since it is past 12:30 am right now (a dangerous time for me to try to think) this still confuses me. It's as if the test "x > y" were true and "y > x" were also true. It's not like integers, in other words. Imagine a method like class Fixnum def best_of(other) self > other ? self : other end end Unless I've done something stupid, this means 6.best_of(4) # 6 4.best_of(6) # 6 - same answer You're probably shaking your head at my stating the obvious, so I'll shut up now. > Having said that, I'm not familiar with the game, so here are some > testcases which capture my assumptions of what I thought you meant :) (snip) That's precisely what I meant. Your assumptions are correct. Cheers, Hal