Smarandache prime-digital sequence: Difference between revisions
Content added Content deleted
(add freebasic) |
|||
Line 527: | Line 527: | ||
100000th member: 23325232253 |
100000th member: 23325232253 |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<lang freebasic> |
|||
function isprime( n as ulongint ) as boolean |
|||
if n < 2 then return false |
|||
if n = 2 then return true |
|||
if n mod 2 = 0 then return false |
|||
for i as uinteger = 3 to int(sqr(n))+1 step 2 |
|||
if n mod i = 0 then return false |
|||
next i |
|||
return true |
|||
end function |
|||
dim as integer smar(1 to 100), count = 1, i = 1, digit, j |
|||
smar(1) = 2 |
|||
print 1, 2 |
|||
while count < 100 |
|||
i += 2 |
|||
if not isprime(i) then continue while |
|||
for j = 1 to len(str(i)) |
|||
digit = val(mid(str(i),j,1)) |
|||
if not isprime(digit) then continue while |
|||
next j |
|||
count += 1 |
|||
smar(count) = i |
|||
if count = 100 orelse count <=25 then |
|||
print count, smar(count) |
|||
end if |
|||
wend</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 2 |
|||
2 3 |
|||
3 5 |
|||
4 7 |
|||
5 23 |
|||
6 37 |
|||
7 53 |
|||
8 73 |
|||
9 223 |
|||
10 227 |
|||
11 233 |
|||
12 257 |
|||
13 277 |
|||
14 337 |
|||
15 353 |
|||
16 373 |
|||
17 523 |
|||
18 557 |
|||
19 577 |
|||
20 727 |
|||
21 733 |
|||
22 757 |
|||
23 773 |
|||
24 2237 |
|||
25 2273 |
|||
100 33223</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 723: | Line 780: | ||
Same as before. |
Same as before. |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
Using the optimized approach of generated numbers from prime digits and testing for primality. |
Using the optimized approach of generated numbers from prime digits and testing for primality. |