On 18/11/05, Ruby Quiz <james / grayproductions.net> wrote:
> The three rules of Ruby Quiz:
>
> 1.  Please do not post any solutions or spoiler discussion for this quiz until
> 48 hours have passed from the time on this message.
>
> 2.  Support Ruby Quiz by submitting ideas as often as you can:
>
> http://www.rubyquiz.com/
>
> 3.  Enjoy!
>
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>
> The card game of Euchre has an unusual ordering of cards in the hand.  This
> week's Ruby Quiz is to take a random Euchre hand and sort it.
>
> The first thing you need to know is that Euchre is played with a small deck of
> cards.  Four suits are used Diamonds (d), Clubs (c), Spades (s), and Hearts (h),
> but each suit has only the cards Nine (9), Ten (T), Jack (J), Queen (Q), King
> (K), and Ace (A).  The cards are generally ordered as I just listed them, Nine
> being the low card and Ace the high card.  The exception is the "Bowers".
>
> When a Euchre hand is started, the first task is to select a Trump suit.  How
> that's done is not important, just know that one suit is always different from
> the rest.  Trump is the best suit, valued higher than the other three suits
> (which are basically equal).  In the Trump suit, the card order changes.
>
> The first oddity of Trump is that the Jack of the selected suit becomes the
> Right Bower, the highest ranked Trump card.  The second oddity is that the other
> Jack of the same color (Diamonds and Hearts are red while Clubs and Spades are
> black) becomes the Left Bower, the second highest Trump card.  This card is
> considered to be of the Trump suit for the rest of the hand.  For example, if
> Spades is selected as Trump, the order of Spades becomes (lowest to highest):
> 9s, Ts, Qs, Ks, As, Jc, and Js.  All other suits run Nine to Ace, save that
> Clubs will be short a Jack.
>
> The three non-Trump suits are equal, but it is good interface to sort the by
> suit alternating red, black, red, and black, I think.  Especially with a GUI,
> this makes it easier to understand the hand.
>
> Input (on STDIN) will be a line containing the Trump suit, followed by five
> lines containing a Euchre hand. For example:
>
>         Diamonds
>         Kc
>         Jh
>         Kd
>         Td
>         Ah
>
> Your script should output (to STDOUT) the Trump suit, followed by the cards in
> sorted order (highest card first):
>
>         Diamonds
>         Jh
>         Kd
>         Td
>         Kc
>         Ah
>
> Here's a script that will feed your program random hands:
>
>         #!/usr/local/bin/ruby -w
>
>         # build a Euchre deck
>         cards = Array.new
>         %w{9 T J Q K A}.each do |face|
>           %w{d c s h}.each do |suit|
>             cards << face + suit
>           end
>         end
>
>         # choose trump
>         puts %w{Diamonds Clubs Spades Hearts}[rand(4)]
>
>         # deal a hand
>         cards = cards.sort_by { rand }
>         puts cards[0..4]
>
> One last thought:  If accuracy is our ultimate goal here, how will you know your
> output is correct?
>
>

Hello James,

I have to admit that I do not totally understand. Why is in the
example the King of Clubs higher than the Ace of hearts. I thought an
Ace would be higher than a King and Clubs and Hearts are equal except
for the Jack if the trump is Diamond.

And secondly I do not understand the paragraph about the red-black sort order.

cheers,

Brian
--
http://ruby.brian-schroeder.de/

Stringed instrument chords: http://chordlist.brian-schroeder.de/