------ art_32607_12529647.1132557139510 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline OOPS! I was just looking at ways I could golf my solution and I realized I had a big bug: replace VAL = [?A,?Q,?K,?J,?T,?9] with VAL = [?A,?K,?Q,?J,?T,?9] Doh! On 11/20/05, Adam Shelly <adam.shelly / gmail.com> wrote: > > Here's mine. I believe it always handles red-black ordering correctly even > with empty suits. > > class EuchreHand > SUIT = [?c,?d,?s,?h] > VAL = [?A,?Q,?K,?J,?T,?9] > def initialize input > @trump = input.shift > @hand = {} > 4.times {|s| @hand[SUIT[s]]=[]} > input.each{|card| @hand[card[1]] << card[0] } > end > def display > puts @trump > t=SUIT.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 = SUIT[s] > @hand[suit].sort{|a,b| VAL.index(a)<=>VAL.index(b)}.each{|v| > puts [v,suit].pack('c*') > } > end > end > > if __FILE__ == $0 > input =readlines > e = EuchreHand.new(input) > e.display > end > > ---- > -Adam > ------ art_32607_12529647.1132557139510--