Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
23
Task/Goldbachs-comet/Pluto/goldbachs-comet-1.pluto
Normal file
23
Task/Goldbachs-comet/Pluto/goldbachs-comet-1.pluto
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
69
Task/Goldbachs-comet/Pluto/goldbachs-comet-2.pluto
Normal file
69
Task/Goldbachs-comet/Pluto/goldbachs-comet-2.pluto
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
do -- create a bitmap of Goldbach's Comet
|
||||
|
||||
local int = require( "int" ) -- RC Pluto integer library, inc. prime utilities
|
||||
require( "bitmap" ) -- RC bitmap library
|
||||
|
||||
local bmp = bitmap.of( 400, 240, color.black, "Goldbachs_comet_Pluto" )
|
||||
|
||||
local maxG <const>, maxP <const> = 4000, 1_000_000
|
||||
local rootMaxP <const>, halfMaxG <const> = math.floor( math.sqrt( maxP ) ), maxG // 2
|
||||
|
||||
local prime <const> = int.arecomps( maxP ):map( | v | -> not v ) -- sieve the primes to maxP
|
||||
|
||||
local G <const> = {} -- construct a table of G numbers
|
||||
for i = 1, maxG do G[ i ] = 0 end
|
||||
G[ 4 ] = 1 -- 4 is the only sum of 2 even primes
|
||||
for i = 3, halfMaxG, 2 do
|
||||
if prime[ i ] then
|
||||
G[ i + i ] += 1
|
||||
for j = i + 2, maxG - i do
|
||||
if prime[ j ] then
|
||||
G[ i + j ] += 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print the first few G numbers to the bitmap - 8x8 charaxters
|
||||
local c, tx, ty = 0, 2, 2
|
||||
for i = 4, 202, 2 do
|
||||
c += 1
|
||||
bmp:text( string.format( "%3d", G[ i ] ), tx, ty, color.white, 1 )
|
||||
if c % 10 != 0 then
|
||||
tx += 24
|
||||
else
|
||||
tx, ty = 2, ty + 10
|
||||
end
|
||||
end
|
||||
local Gm = 0
|
||||
for i = 3, maxP // 2, 2 do
|
||||
if prime[ i ] then
|
||||
if prime[ maxP - i ] then Gm += 1 end
|
||||
end
|
||||
end
|
||||
-- print G(1_000_000) to the bitmap
|
||||
bmp:text( string.format( "G(%d): %d", maxP, Gm ), 2, ty + 10, color.white, 1 )
|
||||
for i = 2, maxG - 10, 10 do
|
||||
local maxY = 0
|
||||
local x <const> = i // 10
|
||||
for j = i, i + 8, 2 do
|
||||
if G[ j ] > 0 then
|
||||
local y <const> = 240 - G[ j ]
|
||||
bmp:set( x, y, switch bmp:get( x, y ) do
|
||||
case color.black -> color.orange
|
||||
case color.orange -> color.yellow
|
||||
default -> color.white
|
||||
end
|
||||
)
|
||||
if y > maxY then maxY = y end
|
||||
end
|
||||
end
|
||||
-- we're going to save it as a png, so convert from BGR to RGb
|
||||
for j = 1, maxY do
|
||||
local bgr <const> = bmp:get( x, j )
|
||||
if bgr != color.black then
|
||||
bmp:set( x, j, bmp.flipColor( bgr ) )
|
||||
end
|
||||
end
|
||||
end
|
||||
bmp:view( true )
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue