Created
October 27, 2018 14:41
-
-
Save SqrtNegInf/f3e9ef2807f225946871b385aeae6826 to your computer and use it in GitHub Desktop.
Perl - Rosettacode Prime_conspiracy task
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use ntheory qw/forprimes nth_prime/; | |
my $upto = 100_000_000; | |
my @freq; | |
my($this_digit,$last_digit)=(2,0); | |
forprimes { | |
($last_digit,$this_digit) = ($this_digit, $_ % 10); | |
$freq[$last_digit . $this_digit]++; | |
} 3,nth_prime($upto); | |
print "$upto first primes. Transitions prime % 10 → next-prime % 10.\n"; | |
for my $i (0..$#freq) { | |
next unless $freq[$i]; | |
printf "%s → %s count:\t%7d\tfrequency: %4.2f %%\n", | |
substr($i,0,1), substr($i,1,1), $freq[$i], 100*$freq[$i]/$upto | |
} |
TIL... Yup, it all works as advertised. And I'm always in favor of keeping it simple, and putting just the best version on RC, so a vote to 'replace'.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would you recommend replacing the code on RC or adding it as an alternative?