How to resolve the algorithm Ormiston triples step by step in the Perl programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ormiston triples step by step in the Perl programming language
Table of Contents
Problem Statement
An Ormiston triple is three consecutive prime numbers which are anagrams, i.e. contain the same decimal digits but in a different order. The three consecutive primes (11117123, 11117213, 11117321) are an Ormiston triple.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ormiston triples step by step in the Perl programming language
Source code in the perl programming language
use strict;
use warnings;
use feature 'say';
use ntheory <primes vecfirstidx>;
my(@O,$pairs);
my @primes = @{ primes(1,1e8) };
my @A = map { join '', sort split '', $_ } @primes;
for (1..$#primes-2) { push @O, $_ if $A[$_] eq $A[$_+1] and $A[$_] eq $A[$_+2] }
say "First 25 Ormiston triples:";
$pairs .= sprintf "%8d, ", $primes[$_] for @O[0..24];
$pairs =~ s/, $//;
say $pairs =~ s/.{50}\K/\n/gr;
for (
[1e8, 'one hundred million'],
[1e9, 'one billion'],
) {
my($limit,$text) = @$_;
my $i = vecfirstidx { $primes[$_] >= $limit } @O;
printf "%3d Ormiston triples before %s\n", $i, $text;
}
You may also check:How to resolve the algorithm Increment a numerical string step by step in the Prolog programming language
You may also check:How to resolve the algorithm Compare length of two strings step by step in the Haskell programming language
You may also check:How to resolve the algorithm Pell numbers step by step in the Quackery programming language
You may also check:How to resolve the algorithm Web scraping step by step in the PureBasic programming language
You may also check:How to resolve the algorithm Keyboard input/Keypress check step by step in the PowerShell programming language