I'm sorry to tell you, but that still won't work... (try choosing 1/1 -- two of diamonds). You just shifted (mirrored) the problem...

Now it still works for anything on 1/1 .. 4/4 in the original table...

click Read more below for the solution...

use @cards = reverse @cards;, since that's what you're doing when you collect the cards,(stacking them left to right, top to botton) and then put them up on the table again...

Original numbering was fine, you have to twist your solution lookup, however.

Updated : Here's a diff to your (semi-original) solution:

5c5 < my ($column, $row, @cards2); --- > my ($column, $row); 33,39c33 < for (my $i = 0; $i <= $#cards; $i++) { < for (my $j = 0; $j <= $#cards; $j++) { < $cards2[$i][$j] = $cards[$j][$i]; < $cards2[$j][$i] = $cards[$i][$j]; < } < } < @cards = @cards2; --- > @cards = reverse @cards; 51c45 < print "\n\nYour card is: $cards[$column-1][$row-1][0]$cards[$column- +1][$row-1][1]\n\n"; --- > print "\n\nYour card is: $cards[$row-1][$column-1][0]$cards[$row-1][ +$column-1][1]\n\n"; 56c50 < $i = 4; --- > $i = 1; 66c60 < $i -= 1; --- > $i++;

So long,
Flexx


In reply to Re^3: Perl Card Trick by Flexx
in thread Perl Card Trick by Lysander

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.