Does 2012 look prime to you?  Obviously not, thinking base 10 as we
normally do. Nearly as obviously not in any even base we use in software
(octal or hex). But it is prime in quite a few Odd bases - a pleasant
surprise that I caught from a blog link on twitter.
-- 
Bill
@n1vux [email protected]

#! perl
# credit Abigail for regex
#
http://rosettacode.org/wiki/Primality_by_trial_division#By_Regular_Expression_2

# and
# John Cook, Endeavour, Mathematica pseudo code
# http://www.johndcook.com/blog/2012/01/01/2012-is-prime/

use 5.010;

sub f2012base {my $n= shift; 2 * $n**3 + $n + 2 }
sub PrimeQ {local $_ = shift;
(1x$_) !~ /^1?$|^(11+?)\1+$/
 }

# skip base 2 since 2 is invalid digit base 2
for (my $n = 3; $n < 100; $n++)
{ #say $n,'?';
  my $v;
 if (PrimeQ($v=f2012base($n))){ say "2012 base $n is prime; = $v base 10";
} }

_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to