Ascending primes: Difference between revisions

Initial FutureBasic task solution added
(Added Algol W)
(Initial FutureBasic task solution added)
Line 910:
 
Sleep</syntaxhighlight>
 
 
{{out}}
Line 924 ⟶ 925:
 
There are 100 ascending primes.</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 AscendingPrimes( limit as long )
long i, n, mask, num, count = 0
for i = 0 to limit -1
n = 0 : mask = i : num = 1
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\tThere are %ld ascending primes.", count
end fn
 
window 1, @"Ascending Primes", ( 0, 0, 780, 230 )
print
 
CFTimeInterval t
t = fn CACurrentMediaTime
fn AscendingPrimes( 512 )
printf @"\n\tCompute time: %.3f ms\n",(fn CACurrentMediaTime-t)*1000
 
NSLog( @"%@", fn WindowPrintViewString( 1 ) )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
 
2 3 5 7 13 17 19 23 29 37
47 59 67 79 89 127 137 139 149 157
167 179 239 257 269 347 349 359 367 379
389 457 467 479 569 1237 1249 1259 1279 1289
1367 1459 1489 1567 1579 1789 2347 2357 2389 2459
2467 2579 2689 2789 3457 3467 3469 4567 4679 4789
5689 12347 12379 12457 12479 12569 12589 12689 13457 13469
13567 13679 13789 15679 23459 23567 23689 23789 25679 34589
34679 123457 123479 124567 124679 125789 134789 145679 234589 235679
235789 245789 345679 345689 1234789 1235789 1245689 1456789 12356789 23456789
 
There are 100 ascending primes.
 
Compute time: 9.008 ms
</pre>
 
=={{header|Go}}==
723

edits