I might be wrong, but it looks like that ' if (grep /^$card/,
@secondPickedRow) ' could be wrong.

I changed it to

    foreach my $card (@firstPickedRow) {
        foreach my $card2 (@secondPickedRow) {
            if ($card == $card2) {
                $matches++;
                $matchCard = $card;
            }
        }
    }

and it give correct result.

Parker



On Mon, Mar 16, 2015 at 12:15 AM Victor Campos <[email protected]> wrote:

> Hi Mike,
>
> comparing your output with a correct answer, here are the specific test
> cases that you got wrong:
>
> Case #37
> Case #46
> Case #48
> Case #61
> Case #80
> Case #90
> Case #95
>
> I hope it helps you.
>
> Regards,
> Victor.
>
> 2015-03-15 12:25 GMT-03:00 Mike Straw <[email protected]>:
>
> I've coded and run the Magic Trick (Problem A from 2014 qualification
>> round).  I've checked my answers in my output and everything looks correct,
>> but when I upload the file, it keeps saying it's incorrect. I'm thinking
>> maybe it's some formatting aspect I'm missing. Can anyone see what is wrong
>> with my output for this input?
>>
>> Input: http://www.thestraws.net/A-small-practice.in
>>
>> Output: http://www.thestraws.net/a.out
>>
>> Code:
>> #!/usr/bin/perl
>>
>> # Coded using Perl v5.18.2
>>
>> use strict;
>> use Data::Dumper;
>>
>> open IN, "< a.in";
>> open OUT, "> a.out";
>> open TRACE, "> a.trace";
>>
>> chomp(my @fRead = <IN>);
>> close IN;
>>
>> my $numCases = shift @fRead;
>>
>> print TRACE "Number of cases: $numCases\n";
>>
>> CASE:for (my $case = 1; $case <= $numCases; $case++) {
>>     print OUT "Case #$case: ";
>>     my @guess;
>>     my $cards;
>>     for (my $deal = 1; $deal <= 2; $deal++) {
>>         $guess[$deal] = shift @fRead;
>>
>>         for (my $row = 1; $row <= 4; $row++) {
>>             my $thisRow = shift @fRead;
>>
>>             my @theseCards = split ' ', $thisRow;
>>             my $cardNum;
>>             foreach my $card (@theseCards) {
>>                 $cards->[$deal]->[$row]->[$cardNum] = $card;
>>                 $cardNum++;
>>             }
>>         }
>>     }
>>
>>     my $matches = 0;
>>     my $matchCard;
>>
>>     my @firstPickedRow = @{$cards->[1]->[$guess[1]]};
>>     my @secondPickedRow = @{$cards->[2]->[$guess[2]]};
>>     foreach my $card (@firstPickedRow) {
>>         if (grep /^$card/, @secondPickedRow){
>>             $matches++;
>>             $matchCard = $card;
>>         }
>>     }
>>
>>     print TRACE "Case $case: Matches: $matches\n";
>>     print TRACE "Guesses: ($guess[1]) " . join (' ', @firstPickedRow);
>>     print TRACE " / ($guess[2]) " . join (' ', @secondPickedRow) . "\n";
>>     if ($matches == 0) {
>>         print OUT "Volunteer cheated!\n";
>>     } elsif ($matches == 1){
>>         print OUT "$matchCard\n";
>>     } else {
>>         print OUT "Bad magician!\n";
>>     }
>>
>> }
>>
>> close OUT;
>> close TRACE;
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Code Jam" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/google-code/9d3544fb-1887-4227-83d7-ff267e41a162%40googlegroups.com
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google Code Jam" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-code/CAM-fum44mrGaHFf6Qk-XDFK_-G1h3AvWaxSndPMYf6JiSOGhgw%40mail.gmail.com
> <https://groups.google.com/d/msgid/google-code/CAM-fum44mrGaHFf6Qk-XDFK_-G1h3AvWaxSndPMYf6JiSOGhgw%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Code Jam" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-code/CAGDEU-%2B7WcEtbxhUc5AZyps%3Dz%2BH_PN9VPO%2BTSpDQVSfHSp1yGw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to