Think about Loose Coupling PerlMonks

### comment on

 Need Help??
Ok, I ran out of time working on the "brute force" checking, but here is the shell of a program which should reduce the number of numbers which need to be checked to a small enough set. Sorry I could not complete the program (as it was actually starting to be fun. *Smiles*)

```#!/usr/bin/perl
use strict;
use warnings;

use constant MATRIX_DIM => 3; # Set your matrix size here
use constant MAX_NUM    => (10 ** MATRIX_DIM) - 1;

# Since you need to find 2 times the matrix width distinct numbers, yo
+u cannot
# have a divisor greater than the maximum number divided by that produ
+ct.
#
# For example, a 3 x 3 matrix has a maximum number of 999. You need 6
+distinct
# numbers to "solve" the matrix, so the maximum possible divisor would
+ be 166.
# 166 would result in 166, 332, 498, 664, 830, and 996.
#
my \$Divisor = int(MAX_NUM / (MATRIX_DIM * 2));

my @Num;
my @Sol=();

sub CheckSolution
{
my \$pNum=shift;

my @Sol=();

# INCOMPLETE CODE
#
# Place code here which checks every combination of MATRIX_DIM numbe
+rs as rows
# and sees if there are MATRIX_DIM other numbers which can act as co
+lumns.
#
# For example, for a 3 x 3 matrix, this code should go through each
+combination
# of three number (for rows) from the passed array and see if there
+are three
# other numbers which would work with the selected rows as columns.
+This should
# be a workable computation for all smaller matrix sizes.
#

return @Sol;
}

while (\$Divisor >= 1)
{
@Num=();
foreach (1..int(MAX_NUM / \$Divisor))
{
next if ((\$Divisor * \$_) < (MAX_NUM / 10)); #Skip numbers which be
+gin with zero
push @Num, (\$Divisor * \$_);
}
print 'Checking solution for divisor ',\$Divisor,': ',join('-',@Num),
+"\n";

@Sol=CheckSolution(\@Num);
last if (\$#Sol > -1);
\$Divisor--;
}

print "\n";
if (\$#Sol > -1)
{
print 'Maximum divisor is ',\$Divisor,', solution is ',join('-',@Sol)
+,"\n";
}
else
{
print 'No solution found...',"\n";
}

Update: I finished code which will work on any size matrix and posted it Here.

Please note: I use "work" in the loosest terms as solving the 4x4 took 1.5 hours on my notebook.

In reply to Re: Matrix Formation by Rhose
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":

• 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, 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, 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: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?
• See Writeup Formatting Tips and other pages linked from there for more info.

Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2020-11-23 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?