# Euchre Hands (#55)

**URL:** <https://www.ruby-forum.com/t/euchre-hands-55/93289>\
**Category:** Ruby\
**Created:** [November 21, 2005, 7:59am UTC](https://www.ruby-forum.com/t/euchre-hands-55/93289 "2005-11-21T07:59:10Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/3ab097/32.png) [@daniels](https://www.ruby-forum.com/u/daniels)\
**Post date:** [November 21, 2005, 7:59am UTC](https://www.ruby-forum.com/t/euchre-hands-55/93289/1 "2005-11-21T07:59:10Z")

</div>

# 

# 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] removed\_email\_address@domain.invalid\_by {|c| sort\_value©}).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.  
#####################################################################################
