Jump to content

Prime triplets: Difference between revisions

Initial FutureBasic task solution added
(Initial FutureBasic task solution added)
Line 545:
{{out}}<pre>
[ 5 7 11] [ 11 13 17] [ 17 19 23] [ 41 43 47] [ 101 103 107] [ 107 109 113] [ 191 193 197] [ 227 229 233] [ 311 313 317] [ 347 349 353] [ 461 463 467] [ 641 643 647] [ 821 823 827] [ 857 859 863] [ 881 883 887] [1091 1093 1097] [1277 1279 1283] [1301 1303 1307] [1427 1429 1433] [1481 1483 1487] [1487 1489 1493] [1607 1609 1613] [1871 1873 1877] [1997 1999 2003] [2081 2083 2087] [2237 2239 2243] [2267 2269 2273] [2657 2659 2663] [2687 2689 2693] [3251 3253 3257] [3461 3463 3467] [3527 3529 3533] [3671 3673 3677] [3917 3919 3923] [4001 4003 4007] [4127 4129 4133] [4517 4519 4523] [4637 4639 4643] [4787 4789 4793] [4931 4933 4937] [4967 4969 4973] [5231 5233 5237] [5477 5479 5483]
</pre>
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn IsPrime( n as NSUInteger ) as BOOL
BOOL isPrime = YES
NSUInteger i
if n < 2 then exit fn = NO
if n = 2 then exit fn = YES
if n mod 2 == 0 then exit fn = NO
for i = 3 to int(n^.5) step 2
if n mod i == 0 then exit fn = NO
next
end fn = isPrime
 
local fn PrimeTriplets( limit as NSUInteger )
NSUInteger p, i = 1
printf @"---------------------"
printf @"Index P P+2 P+6"
printf @"---------------------"
for p = 3 to limit step 2
if fn IsPrime( p+6 ) == NO then continue
if fn IsPrime( p+2 ) == NO then continue
if fn IsPrime( p ) == NO then continue
printf @"%2lu. %5lu %5lu %5lu", i, p, p+2, p+6
i++
next
end fn
 
fn PrimeTriplets( 5500 )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
---------------------
Index P P+2 P+6
---------------------
1. 5 7 11
2. 11 13 17
3. 17 19 23
4. 41 43 47
5. 101 103 107
6. 107 109 113
7. 191 193 197
8. 227 229 233
9. 311 313 317
10. 347 349 353
11. 461 463 467
12. 641 643 647
13. 821 823 827
14. 857 859 863
15. 881 883 887
16. 1091 1093 1097
17. 1277 1279 1283
18. 1301 1303 1307
19. 1427 1429 1433
20. 1481 1483 1487
21. 1487 1489 1493
22. 1607 1609 1613
23. 1871 1873 1877
24. 1997 1999 2003
25. 2081 2083 2087
26. 2237 2239 2243
27. 2267 2269 2273
28. 2657 2659 2663
29. 2687 2689 2693
30. 3251 3253 3257
31. 3461 3463 3467
32. 3527 3529 3533
33. 3671 3673 3677
34. 3917 3919 3923
35. 4001 4003 4007
36. 4127 4129 4133
37. 4517 4519 4523
38. 4637 4639 4643
39. 4787 4789 4793
40. 4931 4933 4937
41. 4967 4969 4973
42. 5231 5233 5237
43. 5477 5479 5483
</pre>
 
719

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.