Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > [QUIZ SOLUTION] Euchre Hands (#55)

Reply
Thread Tools

[QUIZ SOLUTION] Euchre Hands (#55)

 
 
Daniel Sheppard
Guest
Posts: n/a
 
      11-21-2005
#
# My Solution - unless a mail agent mangles it=20
# (happens with great frequency)
#

class Card
=20 attr_reader :suite, :value
=20 def initialize(string)
=20 @value =3D string[0..-2].upcase
=20 @suite =3D string[-1..-1].downcase
=20 end
=20 def to_i
=20 case @value
=20 when 'J': 11
=20 when 'Q': 12
=20 when 'K': 13
=20 when 'A': 1
=20 else
=20 @value.to_i
=20 end
=20 end
=20 def to_s
=20 @value + @suite
=20 end
end
class EuchreHand
=20 def initialize(trump, cards)
=20 @trump_string =3D trump
=20 @trump =3D trump[0..0].downcase
=20 @cards =3D cards
=20 end
=20 def to_s
=20 ([@trump_string] http://www.velocityreviews.com/forums/(E-Mail Removed)_by {|c| sort_value(c)}).join("\n"=
)
=20 end
=20 private
=20 #there are 6 sections of the sort: jack1, jack2, trump, opp1, same,=

opp2
=20 def sort_value(card)
=20 return [0] if card.value =3D=3D 'J' && card.suite =3D=3D @trump=

=20 same, opposite =3D [['h','d'],['c','s']].partition {|x|
x.include?(@trump)}
=20 same[0].delete(@trump)
=20 same =3D same[0][0]
=20 opposite =3D opposite[0]
=20 return [1] if card.value =3D=3D 'J' && card.suite
=20 suites =3D [@trump, opposite[0], same, opposite[1]]
=20 return [2+suites.index(card.suite),-card.to_i]
=20 end
end

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




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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SUMMARY] Euchre Hands (#55) Ruby Quiz Ruby 2 11-24-2005 04:01 PM
[QUIZ SOLUTION] Euchre Hands (#55) Robin Stocker Ruby 26 11-23-2005 06:29 AM
[SOLUTION] Euchre Hands (#55) Warren Brown Ruby 2 11-23-2005 12:55 AM
[QUIZ] Euchre Hands (#55) Ruby Quiz Ruby 5 11-21-2005 02:23 AM
MSN Euchre through router? Suenet Computer Support 0 11-04-2005 02:46 PM



Advertisments