artist has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
artist
I found an interesting puzzle and here is my attempt to solve it. Let say we have NxN matrix.
By Joining the columns and rows individually, I get the following four formed-numbers. 12,14,28,48 There Common Divisor is '2'. I like to find the matrix with the highest common divisor. Some condtions are..[ [1, 2] [4, 8] ]
- No formed-number should start with 0.
- No two formed-numbers be same.
How I can do with higher dimentions more efficiently? Even for 3X3 with it has to test around billion numbers with my method.[[2,8] [1,4]]
Thanks$| += 1; foreach my $divider (2..9){ print "Divider $divider\n"; N: foreach $n (1111..9999){ next if $n =~ /0\d+/; @n = split //,$n; my $count = 0; my @pairs; my %pairs; foreach (qw(01 02 13 23)){ my($p,$q) = split //; my $num = $n[$p].$n[$q]; push @pairs, $num; next N if defined $pairs{$num}; $pairs{$num} = 1; $count++ if $num % $divider == 0; } print join " " => @pairs,"\n" if $count == 4; } }
artist
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Matrix Formation
by pzbagel (Chaplain) on Jun 17, 2003 at 18:21 UTC | |
Re: Matrix Formation
by Solo (Deacon) on Jun 17, 2003 at 19:28 UTC | |
by tall_man (Parson) on Jun 17, 2003 at 23:20 UTC | |
by CountZero (Bishop) on Jun 17, 2003 at 19:57 UTC | |
Re: Matrix Formation
by CountZero (Bishop) on Jun 17, 2003 at 19:35 UTC | |
Re: Matrix Formation
by Rhose (Priest) on Jun 17, 2003 at 20:07 UTC | |
by tall_man (Parson) on Jun 18, 2003 at 19:38 UTC | |
Re: Matrix Formation
by CountZero (Bishop) on Jun 17, 2003 at 19:53 UTC | |
Re: Matrix Formation
by artist (Parson) on Jun 17, 2003 at 20:45 UTC |
Back to
Seekers of Perl Wisdom