Iccanobif primes: Difference between revisions
Content added Content deleted
m (→{{header|Lua}}: Avoid redefining "next") |
(Added Miniscript) |
||
Line 729: | Line 729: | ||
<pre> |
<pre> |
||
2 3 5 31 43 773 7951 64901 52057 393121 |
2 3 5 31 43 773 7951 64901 52057 393121 |
||
</pre> |
|||
=={{header|MiniScript}}== |
|||
{{Trans|Lua}} |
|||
Using code frommthe [[Reverse a string]] task. |
|||
<syntaxhighlight lang="miniscript"> |
|||
isPrime = function ( n ) |
|||
if n <= 1 or ( n != 2 and n % 2 == 0 ) then |
|||
return false |
|||
end if |
|||
for i in range(3, sqrt(n), 2) |
|||
if n % i == 0 then |
|||
return false |
|||
end if |
|||
end for |
|||
return true |
|||
end function |
|||
reverseString = function( str ) |
|||
revStr = "" |
|||
for i in range(str.len-1, 0) |
|||
revStr = revStr + str[i] |
|||
end for |
|||
return revStr |
|||
end function |
|||
reverseDigits = function( n ) |
|||
return val( reverseString( str( n ) ) ) |
|||
end function |
|||
pCount = 0 |
|||
prev = 0 |
|||
curr = 1 |
|||
out = [] |
|||
while pCount < 10 |
|||
nextF = prev + curr |
|||
prev = curr |
|||
curr = nextF |
|||
rev = reverseDigits( curr ) |
|||
if isPrime( rev ) then |
|||
pCount = pCount + 1 |
|||
out.push( rev ) |
|||
end if |
|||
end while |
|||
print out.join |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
2 3 5 31 43 773 7951 64901 52057 393121 |
|||
</pre> |
</pre> |
||