Triplet of three numbers
- Task
Numbers n such that the three numbers n-1, n+3 and n+5 are all prime. where n < 6000
Julia
<lang julia>using Primes
makesprimetriplet(n) = all(isprime, [n - 1, n + 3, n + 5]) println(" N Prime Triplet\n--------------------------") foreach(n -> println(rpad(n, 6), [n - 1, n + 1, n + 5]), filter(makesprimetriplet, 2:6005))
</lang>
- Output:
N Prime Triplet -------------------------- 8 [7, 9, 13] 14 [13, 15, 19] 38 [37, 39, 43] 68 [67, 69, 73] 98 [97, 99, 103] 104 [103, 105, 109] 194 [193, 195, 199] 224 [223, 225, 229] 278 [277, 279, 283] 308 [307, 309, 313] 458 [457, 459, 463] 614 [613, 615, 619] 824 [823, 825, 829] 854 [853, 855, 859] 878 [877, 879, 883] 1088 [1087, 1089, 1093] 1298 [1297, 1299, 1303] 1424 [1423, 1425, 1429] 1448 [1447, 1449, 1453] 1484 [1483, 1485, 1489] 1664 [1663, 1665, 1669] 1694 [1693, 1695, 1699] 1784 [1783, 1785, 1789] 1868 [1867, 1869, 1873] 1874 [1873, 1875, 1879] 1994 [1993, 1995, 1999] 2084 [2083, 2085, 2089] 2138 [2137, 2139, 2143] 2378 [2377, 2379, 2383] 2684 [2683, 2685, 2689] 2708 [2707, 2709, 2713] 2798 [2797, 2799, 2803] 3164 [3163, 3165, 3169] 3254 [3253, 3255, 3259] 3458 [3457, 3459, 3463] 3464 [3463, 3465, 3469] 3848 [3847, 3849, 3853] 4154 [4153, 4155, 4159] 4514 [4513, 4515, 4519] 4784 [4783, 4785, 4789] 5228 [5227, 5229, 5233] 5414 [5413, 5415, 5419] 5438 [5437, 5439, 5443] 5648 [5647, 5649, 5653] 5654 [5653, 5655, 5659] 5738 [5737, 5739, 5743]
Raku
A weird combination of Cousin primes and Twin primes that are siblings, but known by their neighbor.... I shall dub these Alabama prims.
<lang perl6>.say for grep *.all.is-prime, ^6000 .race.map: { $_-1, $_+3, $_+5 };</lang>
- Output:
(7 11 13) (13 17 19) (37 41 43) (67 71 73) (97 101 103) (103 107 109) (193 197 199) (223 227 229) (277 281 283) (307 311 313) (457 461 463) (613 617 619) (823 827 829) (853 857 859) (877 881 883) (1087 1091 1093) (1297 1301 1303) (1423 1427 1429) (1447 1451 1453) (1483 1487 1489) (1663 1667 1669) (1693 1697 1699) (1783 1787 1789) (1867 1871 1873) (1873 1877 1879) (1993 1997 1999) (2083 2087 2089) (2137 2141 2143) (2377 2381 2383) (2683 2687 2689) (2707 2711 2713) (2797 2801 2803) (3163 3167 3169) (3253 3257 3259) (3457 3461 3463) (3463 3467 3469) (3847 3851 3853) (4153 4157 4159) (4513 4517 4519) (4783 4787 4789) (5227 5231 5233) (5413 5417 5419) (5437 5441 5443) (5647 5651 5653) (5653 5657 5659) (5737 5741 5743)
Ring
<lang ring> load "stdlib.ring" see "working..." + nl see "Numbers n such that the three numbers n-1, n+3 and n+5 are all prime:" + nl row = 0
limit = 6000
for n = 2 to limit-2
bool1 = isprime(n-1) bool2 = isprime(n+3) bool3 = isprime(n+5) bool = bool1 and bool2 and bool3 if bool row = row + 1 see "" + n + " " if row%10 = 0 see nl ok ok
next
see nl + "Found " + row + " primes" + nl see "done..." + nl </lang>
- Output:
working... Numbers n such that the three numbers n-1, n+3 and n+5 are all prime: 8 14 38 68 98 104 194 224 278 308 458 614 824 854 878 1088 1298 1424 1448 1484 1664 1694 1784 1868 1874 1994 2084 2138 2378 2684 2708 2798 3164 3254 3458 3464 3848 4154 4514 4784 5228 5414 5438 5648 5654 5738 Found 46 primes done...
Wren
<lang ecmascript>import "/math" for Int import "/fmt" for Fmt
var c = Int.primeSieve(6003, false) var numbers = [] System.print("Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes:") var n = 4 while (n < 6000) {
if (!c[n-1] && !c[n+3] && !c[n+5]) numbers.add(n) n = n + 2
} for (n in numbers) Fmt.print("$,6d => $,6d", n, [n-1, n+3, n+5]) System.print("\nFound %(numbers.count) such numbers.")</lang>
- Output:
Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes: 8 => 7 11 13 14 => 13 17 19 38 => 37 41 43 68 => 67 71 73 98 => 97 101 103 104 => 103 107 109 194 => 193 197 199 224 => 223 227 229 278 => 277 281 283 308 => 307 311 313 458 => 457 461 463 614 => 613 617 619 824 => 823 827 829 854 => 853 857 859 878 => 877 881 883 1,088 => 1,087 1,091 1,093 1,298 => 1,297 1,301 1,303 1,424 => 1,423 1,427 1,429 1,448 => 1,447 1,451 1,453 1,484 => 1,483 1,487 1,489 1,664 => 1,663 1,667 1,669 1,694 => 1,693 1,697 1,699 1,784 => 1,783 1,787 1,789 1,868 => 1,867 1,871 1,873 1,874 => 1,873 1,877 1,879 1,994 => 1,993 1,997 1,999 2,084 => 2,083 2,087 2,089 2,138 => 2,137 2,141 2,143 2,378 => 2,377 2,381 2,383 2,684 => 2,683 2,687 2,689 2,708 => 2,707 2,711 2,713 2,798 => 2,797 2,801 2,803 3,164 => 3,163 3,167 3,169 3,254 => 3,253 3,257 3,259 3,458 => 3,457 3,461 3,463 3,464 => 3,463 3,467 3,469 3,848 => 3,847 3,851 3,853 4,154 => 4,153 4,157 4,159 4,514 => 4,513 4,517 4,519 4,784 => 4,783 4,787 4,789 5,228 => 5,227 5,231 5,233 5,414 => 5,413 5,417 5,419 5,438 => 5,437 5,441 5,443 5,648 => 5,647 5,651 5,653 5,654 => 5,653 5,657 5,659 5,738 => 5,737 5,741 5,743 Found 46 such numbers.