#
# My Solution - unless a mail agent mangles it 
# (happens with great frequency)
#

class Card
    attr_reader :suite, :value
    def initialize(string)
        @value = string[0..-2].upcase
        @suite = string[-1..-1].downcase
    end
    def to_i
        case @value
            when 'J': 11
            when 'Q': 12
            when 'K': 13
            when 'A': 1
            else
                @value.to_i
        end
    end
    def to_s
        @value + @suite
    end
end
class EuchreHand
    def initialize(trump, cards)
        @trump_string = trump
        @trump = trump[0..0].downcase
        @cards = cards
    end
    def to_s
        ([@trump_string] +@cards.sort_by {|c| sort_value(c)}).join("\n")
    end
    private
    #there are 6 sections of the sort: jack1, jack2, trump, opp1, same,
opp2
    def sort_value(card)
        return [0] if card.value == 'J' && card.suite == @trump
        same, opposite = [['h','d'],['c','s']].partition {|x|
x.include?(@trump)}
        same[0].delete(@trump)
        same = same[0][0]
        opposite = opposite[0]
        return [1] if card.value == 'J' && card.suite
        suites = [@trump, opposite[0], same, opposite[1]]
        return [2+suites.index(card.suite),-card.to_i]
    end
end

cards = ARGF.readlines
puts EuchreHand.new(cards.shift, cards.map {|s| Card.new(s)})




#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################