Honaker primes: Difference between revisions

Honaker primes in Yabasic
(→‎{{header|ALGOL 68}}: Use the "traditional" digit sum calculating method instead of constructing a table.)
(Honaker primes in Yabasic)
Line 651:
and the 10,000th: (286,069, 4,043,749)
</pre>
 
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Periodic_table
// by Jjuanhdez, 09/2022
 
limit = 5 * 10^6
//place = 0
rank = 1
dim prime(limit)
 
for x = 3 to limit step 2
if prime(x) = 0 then
for y = x * x to limit step x + x
prime(y) = 1
next y
end if
next x
 
print "First 50 Honaker primes:"
for x = 3 to limit step 2
if prime(x) = 0 then
rank = rank + 1
if mod(rank, 9) = mod(x, 9) then
if dig_sum(rank) = dig_sum(x) then
place = place + 1
if place <= 50 then
print " ", place using("##"), ": (", rank using("###"), ",", x using("#####"), ")";
if mod(place, 5) = 0 print
end if
if place = 10000 print "\n 10000th honaker prime is at ", rank, " and is ", x
end if
end if
end if
next x
 
sub dig_sum(n)
local sum
 
while n > 0
sum = sum + mod(n, 10)
n = int(n / 10)
end while
 
return sum
end sub
</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
2,122

edits