http://www.perlmonks.org?node_id=197987


in reply to Re: Re: Perl Card Trick
in thread Perl Card Trick

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