1193 is 'rotationally prime' because 1193 and all of it's
rotations (1931, 9311, and 3119) are prime. There is
another set of 4-digit, and two sets of 5-digit rot-prime
numbers. I think that's cool, but I'm not sure why...

Update: changed stop criteria in sub primelist from
test/2 to sqrt(test). Thanks to larsen.

Also, there are two sets of 6 digit rot-prime numbers.

YuckFoo

`#!/usr/bin/perl
use strict;
my ($DIGITS) = (5);
my ($list, $item);
$list = primelist(10**$DIGITS);
$list = rotatelist($list);
for $item (@{$list}) { print "$item\n"; }
#-----------------------------------------------------------
sub rotatelist {
my ($primes) = @_;
my (@list, %phash, $prime, $sum);
my ($rotations, $rotation);
@phash{@{$primes}} = (1) x @{$primes};
for $prime (@{$primes}) {
$rotations = rotations($prime);
if ($prime == $rotations->[0]) {
$sum = 0;
for $rotation (@{$rotations}) {
$sum += $phash{$rotation};
}
if ($sum == @{$rotations}) { push (@list, $prime); }
}
}
return \@list;
}
#-----------------------------------------------------------
sub rotations {
my ($num) = @_;
my (@list, @digs, $i);
@digs = split('', $num);
for ($i = 0; $i < length($num); $i++) {
push (@digs, shift(@digs));
push (@list, join ('', @digs) + 0);
}
@list = sort(@list);
return \@list;
}
#-----------------------------------------------------------
sub primelist {
my ($max) = @_;
my ($test, $stop, $isprime, $prime);
my (@primes) = qw(2);
for ($test = 3; $test < $max; $test++) {
$stop = sqrt($test);
$isprime = 1;
for $prime (@primes) {
if ($prime > $stop) { last; }
if ($test % $prime == 0) {
$isprime = 0;
last;
}
}
if ($isprime) { push (@primes, $test); }
}
return \@primes;
}
`

Comment onRotationally Prime NumbersDownloadCode