Ormiston pairs
An Ormiston pair is two consecutive prime numbers which are anagrams, i.e. contain the same decimal digits but in a different order.
Ormiston pairs is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
(1913, 1931) is the first such pair.
- Task
- Find and show the first 30 Ormiston pairs.
- Find and show the count of Ormiston pairs up to one million.
- Stretch
- Find and show the count of Ormiston pairs up to ten million.
Raku
use Lingua::EN::Numbers;
use List::Divvy;
my @primes = lazy (^∞).hyper.grep: &is-prime;
my @Ormistons = @primes.kv.map: { ($^value, @primes[$^key+1]) if $^value.comb.Bag eqv @primes[$^key+1].comb.Bag };
say @Ormistons[^30].batch(3)».map( { "({.[0].fmt: "%5d"}, {.[1].fmt: "%5d"})" } ).join: "\n";
say '';
say +@Ormistons.&before( *[1] > $_ ) ~ " Ormiston pairs before " ~ .Int.&cardinal for 1e5, 1e6, 1e7;
- Output:
( 1913, 1931) (18379, 18397) (19013, 19031) (25013, 25031) (34613, 34631) (35617, 35671) (35879, 35897) (36979, 36997) (37379, 37397) (37813, 37831) (40013, 40031) (40213, 40231) (40639, 40693) (45613, 45631) (48091, 48109) (49279, 49297) (51613, 51631) (55313, 55331) (56179, 56197) (56713, 56731) (58613, 58631) (63079, 63097) (63179, 63197) (64091, 64109) (65479, 65497) (66413, 66431) (74779, 74797) (75913, 75931) (76213, 76231) (76579, 76597) 40 Ormiston pairs before one hundred thousand 382 Ormiston pairs before one million 3722 Ormiston pairs before ten million