Ormiston pairs: Difference between revisions

→‎{{header|Haskell}}: Fractionally more efficient
(Added output.)
(→‎{{header|Haskell}}: Fractionally more efficient)
(4 intermediate revisions by 4 users not shown)
Line 800:
326,926 Ormiston pairs before 1,000,000,000
</pre>
 
=={{header|Haskell}}==
 
<syntaxhighlight lang=haskell>import Data.List (sort)
import Data.Numbers.Primes (primes)
 
---------------------- ORMISTON PAIRS --------------------
 
ormistonPairs :: [(Int, Int)]
ormistonPairs =
[ (fst a, fst b)
| (a, b) <- zip primeDigits (tail primeDigits),
snd a == snd b
]
 
primeDigits :: [(Int, String)]
primeDigits = (,) <*> (sort . show) <$> primes
 
--------------------------- TEST -------------------------
main :: IO ()
main =
putStrLn "First 30 Ormiston pairs:"
>> mapM_ print (take 30 ormistonPairs)
>> putStrLn "\nCount of Ormistons up to 1,000,000:"
>> print (length (takeWhile ((<= 1000000) . snd) ormistonPairs))</syntaxhighlight>
 
{{Out}}
<pre>First 30 Ormiston pairs:
(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)
 
Count of Ormistons up to 1,000,000:
382</pre>
 
=={{header|J}}==
Line 824 ⟶ 885:
+/isorm i.&.(p:inv) 1e7 NB. number of Ormiston pairs less than 1e7
3722</syntaxhighlight>
 
=={{header|jq}}==
{{works with|jq}}
Line 893 ⟶ 955:
3722 Ormiston pairs before 10000000
</pre>
 
=={{header|Julia}}==
{{trans|Python}}
<syntaxhighlight lang="Julia">using Primes
 
function testormistons(toshow = 30, lim = 1_000_000)
pri = primes(lim)
csort = [sort!(collect(string(i))) for i in pri]
ormistons = [(pri[i - 1], pri[i]) for i in 2:lastindex(pri) if csort[i - 1] == csort[i]]
println("First $toshow Ormiston pairs under $lim:")
for (i, o) in enumerate(ormistons)
i > toshow && break
print("(", lpad(first(o), 6), lpad(last(o), 6), " )", i % 5 == 0 ? "\n" : " ")
end
println("\n", length(ormistons), " is the count of Ormiston pairs up to one million.")
end
 
testormistons()
</syntaxhighlight>{{out}} Same as Python example.
 
=={{header|Nim}}==
Line 1,792 ⟶ 1,873:
</pre>
 
 
=={{header|RPL}}==
{{works with|HP|49}}
« →STR { 10 } 0 CON
1 PICK3 SIZE '''FOR''' j
OVER j DUP SUB STR→ 1 +
DUP2 GET 1 + PUT
'''NEXT''' NIP
» '<span style="color:blue">DIGCNT</span>' STO <span style="color:grey">''@ ( n → [ count0 .. count9 ] ) ''</span>
« 0 { } 2 3
'''WHILE''' DUP 1E6 < '''REPEAT'''
'''IF''' DUP2 <span style="color:blue">DIGCNT</span> SWAP <span style="color:blue">DIGCNT</span> == '''THEN'''
'''IF''' PICK3 SIZE 30 < '''THEN'''
DUP2 2 →LIST 1 →LIST 4 ROLL SWAP + UNROT
'''END'''
4 ROLL 1 + 4 ROLLD
'''END'''
NIP DUP NEXTPRIME
'''END''' DROP2 SWAP
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
2: {{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}}
1: 382
</pre>
 
=={{header|Rust}}==
Line 1,873 ⟶ 1,980:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./math" for Int
import "./fmt" for Fmt
 
9,655

edits