Descending primes: Difference between revisions

Initial FutureBasic task solution added
(Initial FutureBasic task solution added)
Line 684:
</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
 
void local fn DesecendingPrimes( limit as long )
long i, n, mask, num, count = 0
for i = 0 to limit -1
n = 0 : mask = i : num = 9
while ( mask )
if mask & 1 then n = n * 10 + num
mask = mask >> 1
num--
wend
mda(i) = n
next
mda_sort @"compare:"
for i = 1 to mda_count (0) - 1
n = mda_integer(i)
if ( fn IsPrime( n ) )
printf @"%10ld\b", n
count++
if count mod 10 == 0 then print
end if
next
printf @"\n\n\tThere are %ld descending primes.", count
end fn
 
window 1, @"Desecending Primes", ( 0, 0, 780, 230 )
print
 
CFTimeInterval t
t = fn CACurrentMediaTime
fn DesecendingPrimes( 512 )
printf @"\n\tCompute time: %.3f ms\n",(fn CACurrentMediaTime-t)*1000
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
2 3 5 7 31 41 43 53 61 71
73 83 97 421 431 521 541 631 641 643
653 743 751 761 821 853 863 941 953 971
983 5431 6421 6521 7321 7541 7621 7643 8431 8521
8543 8641 8731 8741 8753 8761 9421 9431 9521 9631
9643 9721 9743 9851 9871 75431 76421 76541 76543 86531
87421 87541 87631 87641 87643 94321 96431 97651 98321 98543
98621 98641 98731 764321 865321 876431 975421 986543 987541 987631
8764321 8765321 9754321 9875321 97654321 98764321 98765431
 
There are 87 descending primes.
 
Compute time: 8.976 ms
</pre>
=={{header|Go}}==
{{trans|Wren}}
717

edits