Oh wow, so it is. Sorry, I didn't look at your code since you didn't mention that you had gone outside the parameters provided so I didn't think that you had done what I was doing.
In penance, here is a script that shows the repeat length for 1/$n only when that length isn't "boring". If $n is prime a repeat length of $n1 is "boring". If $n is composite, the boring length is the max repeat length of its prime factors.
#!/usr/bin/perl w
use strict;
Main();
exit();
sub repDig
{
my( $den, $num )= @_;
$num = 1;
my $rem= $num % $den;
my %seen;
my $rep= '';
while( 1 ) {
$rem *= 10;
last
if exists $seen{$rem};
$seen{$rem}= length( $rep );
$rep .= int( $rem / $den );
$rem %= $den;
}
substr( $rep, 0, $seen{$rem} )= '';
return $rep;
}
sub factor
{
my( $r )= @_;
my $f= '';
my @f;
my $p= 2;
while( 1 < $r ) {
my $q= int( $r / $p );
last
if $q < $p;
my $e= 0;
while( $r == $q*$p && $q ) {
$e++;
$r= $q;
$q= int( $r / $p );
}
if( $e ) {
push @f, $p;
$f .= "*$p";
$f .= "^$e"
if 1 < $e;
}
$p += 2==$p ? 1 : 2;
}
if( 1 < $r  ! @f ) {
push @f, $r;
$f .= "*$r";
}
substr( $f, 0, 1 )= '';
return $f, @f;
}
sub Main
{
my $dem= 1;
my %r;
while( 1 ) {
my( $f, @f )= factor( ++$dem );
my $r= repDig( $dem );
$r= $r ? length($r) : 0;
if( $f eq $dem ) {
$r{$dem}= $r;
next
if $r == $dem1;
} else {
my $max= 0;
for( @f ) {
$max= $r{$_}
if $max < $r{$_};
}
next
if $r == $max;
}
printf "%8d: 1/%s\n", $r, $f;
}
}
and the first few lines of output:
My favotite is: 42: 1/7^2
Now demonstrate your understanding by correctly predicting a number with a repeat length of 11 or 25.
