From: Adam Shelly Date: 2005-11-21T15:49:48+09:00 Subject: Re: [QUIZ SOLUTION] Euchre Hands (#55) ------=_Part_32527_30812562.1132555782725 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Here's mine. I believe it always handles red-black ordering correctly even with empty suits. class EuchreHand SUIT =3D [?c,?d,?s,?h] VAL =3D [?A,?Q,?K,?J,?T,?9] def initialize input @trump =3D input.shift @hand =3D {} 4.times {|s| @hand[SUIT[s]]=3D[]} input.each{|card| @hand[card[1]] << card[0] } end def display puts @trump t=3DSUIT.index(@trump.downcase[0]) get_jacks(SUIT[t]) get_jacks(SUIT[(t+2)%4]) if @hand[SUIT[(t+1)%4]].empty? t.downto(0){|s| show_suit s} (3).downto(t+1) {|s| show_suit s} else (t..3).each {|s| show_suit s} (0...t).each {|s| show_suit s} end end def get_jacks suit if @hand[suit].include? ?J puts [?J,suit].pack('c*') @hand[suit].delete(?J) end end def show_suit s suit =3D SUIT[s] @hand[suit].sort{|a,b| VAL.index(a)<=3D>VAL.index(b)}.each{|v| puts [v,suit].pack('c*') } end end if __FILE__ =3D=3D $0 input =3Dreadlines e =3D EuchreHand.new(input) e.display end ---- -Adam ------=_Part_32527_30812562.1132555782725--