23 lines
785 B
Text
23 lines
785 B
Text
do -- Goldbach's comet, translation of Lua
|
|
|
|
local int = require( "int" ) -- RC Pluto integer library, inc. prime utilities
|
|
|
|
local function goldbach( n : number ) : number
|
|
local count = 0
|
|
for i = 1, n // 2 do
|
|
if int.isprime( i ) and int.isprime( n - i ) then
|
|
++ count
|
|
end
|
|
end
|
|
return count
|
|
end
|
|
|
|
print( "The first 100 G numbers:" )
|
|
print( range( 100 ):map( | n | -> string.format( "%2d"..if n % 10 == 0 then "\n" else " " end
|
|
, goldbach( 2 + n * 2 )
|
|
)
|
|
)
|
|
:concat( "" )
|
|
)
|
|
print( $"G(1000000) = { goldbach( 1_000_000 ) }" )
|
|
end
|