Iccanobif primes: Difference between revisions

Initial FutureBasic task solution added
(Created Nim solution.)
(Initial FutureBasic task solution added)
Line 410:
<pre>
Same as Wren example.
</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 ReverseNumber( n as NSUInteger )
NSUInteger reverse
if n < 10 then exit fn = n
reverse = 0
while (n > 0)
reverse = 10 * reverse + (n mod 10)
n = int(n / 10)
wend
end fn = reverse
 
local fn IccanobifPrimes( limit as NSUInteger )
NSUInteger cnt = 0, prev = 0, curr = 1, sgte, rev
printf @"First 11 IccanobiF primes:"
while (cnt < limit)
sgte = prev + curr
prev = curr
curr = sgte
rev = fn ReverseNumber(curr)
if fn IsPrime(rev)
// Iccanobif prime found
cnt++
printf @"%2lu. %lu", cnt, rev
end if
wend
end fn
 
fn IccanobifPrimes( 11 )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
First 11 Iccanobif primes:
1. 2
2. 3
3, 5
4. 31
5. 43
6, 773
7. 7951
8. 64901
9. 52057
10. 393121
11. 56577108676171
</pre>
 
715

edits