Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here is a possible implementation of CheckSolution (for 3x3 only -- generalization is possible but it is left as an exercise for the reader):
sub CheckSolution { my $pNum = shift; my @Sol=(); # Do some easy pair checks first. my @digmap; foreach my $n (@$pNum) { my @digits = split //,$n; foreach (0..$#digits) { push @{$digmap[$_]->{$digits[$_]}},$n; } } # Two or more with same first digit. my $ref0 = $digmap[0]; my @lst0 = grep { scalar(@{$ref0->{$_}}) > 1 } keys %$ref0; return @Sol if (! scalar(@lst0)); # Two or more with same middle digit. my $ref1 = $digmap[1]; my @lst1 = grep { scalar(@{$ref1->{$_}}) > 1 } keys %$ref1; return @Sol if (! scalar(@lst1)); # Two or more with same last digit my $ref2 = $digmap[2]; my @lst2 = grep { scalar(@{$ref2->{$_}}) > 1 } keys %$ref2; return @Sol if (! scalar(@lst2)); #print "Passed pair test\n"; # Use these lists for candidates for the three row positions. my @uppers = map { @{$ref0->{$_}} } @lst0; my @centers = map { @{$ref1->{$_}} } @lst1; my @bottoms = map { @{$ref2->{$_}} } @lst2; my ($upper, $center, $bottom); my ($a, $b, $c, $d, $e, $f, $g, $h, $i); my ($adg, $beh, $cfi); # hash to simplify checking for duplicates. my %wholeset = map { $_ => 1 } @$pNum; my (%t1, %t2, %t3); foreach $upper (@uppers) { %t1 = %wholeset; $t1{$upper} = 0; foreach $center (@centers) { next if (! $t1{$center}); %t2 = %t1; $t2{$center} = 0; foreach $bottom (@bottoms) { next if (! $t2{$bottom}); %t3 = %t2; $t3{$bottom} = 0; ($a, $b, $c) = split //,$upper; ($d, $e, $f) = split //,$center; ($g, $h, $i) = split //,$bottom; $adg = $a . $d . $g; next if (! $t3{$adg}); $t3{$adg} = 0; $beh = $b . $e . $h; next if (! $t3{$beh}); $t3{$beh} = 0; $cfi = $c . $f . $i; next if (! $t3{$cfi}); # Solution found - return it. return ($upper, $center, $bottom); } # bottom } # center } #upper return @Sol; }
I tried this and it found the 132-792-660 (divisor 44) case in about 4 seconds.

In reply to Re: Re: Matrix Formation by tall_man
in thread Matrix Formation by artist

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (7)
As of 2024-04-23 17:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found