Triplet of three numbers: Difference between revisions

Add CLU
(Added solution for Action!)
(Add CLU)
Line 685:
Up to 100,000,000 there are 55,556 prime triples, of which 686 were found to be adjacent.
</pre>
 
=={{header|CLU}}==
<lang clu>LIMIT = 6000
 
isqrt = proc (s: int) returns (int)
x0: int := s/2
if x0=0 then return(s) end
x1: int := (x0 + s/x0)/2
while x1 < x0 do
x0 := x1
x1 := (x0 + s/x0)/2
end
return(x0)
end isqrt
 
sieve = proc (n: int) returns (array[bool])
prime: array[bool] := array[bool]$fill(2,n-1,true)
for p: int in int$from_to(2,isqrt(n)) do
if prime[p] then
for c: int in int$from_to_by(p*p,n,p) do
prime[c] := false
end
end
end
return(prime)
end sieve
 
triplet = proc (n: int, prime: array[bool]) returns (bool)
return(prime[n-1] & prime[n+3] & prime[n+5])
except when bounds: return(false) end
end triplet
 
start_up = proc ()
po: stream := stream$primary_output()
prime: array[bool] := sieve(LIMIT)
for i: int in int$from_to(2,LIMIT) do
if triplet(i, prime) then
stream$putright(po, int$unparse(i), 4)
stream$puts(po, ": ")
stream$putright(po, int$unparse(i-1), 4)
stream$puts(po, ", ")
stream$putright(po, int$unparse(i+3), 4)
stream$puts(po, ", ")
stream$putright(po, int$unparse(i+5), 4)
stream$putl(po, "")
end
end
end start_up</lang>
{{out}}
<pre style='height:50ex;'> 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
1088: 1087, 1091, 1093
1298: 1297, 1301, 1303
1424: 1423, 1427, 1429
1448: 1447, 1451, 1453
1484: 1483, 1487, 1489
1664: 1663, 1667, 1669
1694: 1693, 1697, 1699
1784: 1783, 1787, 1789
1868: 1867, 1871, 1873
1874: 1873, 1877, 1879
1994: 1993, 1997, 1999
2084: 2083, 2087, 2089
2138: 2137, 2141, 2143
2378: 2377, 2381, 2383
2684: 2683, 2687, 2689
2708: 2707, 2711, 2713
2798: 2797, 2801, 2803
3164: 3163, 3167, 3169
3254: 3253, 3257, 3259
3458: 3457, 3461, 3463
3464: 3463, 3467, 3469
3848: 3847, 3851, 3853
4154: 4153, 4157, 4159
4514: 4513, 4517, 4519
4784: 4783, 4787, 4789
5228: 5227, 5231, 5233
5414: 5413, 5417, 5419
5438: 5437, 5441, 5443
5648: 5647, 5651, 5653
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743</pre>
 
=={{header|Cowgol}}==
Line 771 ⟶ 866:
5654: 5653, 5657, 5659
5738: 5737, 5741, 5743</pre>
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
2,114

edits