Euclid-Mullin sequence: Difference between revisions
Content added Content deleted
(Added Lua) |
(Added Miniscript) |
||
Line 626: | Line 626: | ||
end |
end |
||
end |
end |
||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
2 3 7 43 13 53 5 6221671 |
|||
</pre> |
|||
=={{header|MiniScript}}== |
|||
{{Trans|Lua}} |
|||
<syntaxhighlight lang="miniscript"> |
|||
// find elements of the Euclid-Mullin sequence: starting from 2, |
|||
// the next element is the smallest prime factor of 1 + the product |
|||
// of the previous elements |
|||
seq = [2] |
|||
product = 2 |
|||
for i in range( 2, 8 ) |
|||
nextV = product + 1 |
|||
// find the first prime factor of nextV |
|||
p = 3 |
|||
found = false |
|||
while p * p <= nextV and not found |
|||
found = nextV % p == 0 |
|||
if not found then p = p + 2 |
|||
end while |
|||
if found then nextV = p |
|||
seq.push( nextV ) |
|||
product = product * nextV |
|||
end for |
|||
print seq.join( " ") |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||
{{out}} |
{{out}} |