Skip to content

Instantly share code, notes, and snippets.

@sharpobject
Created February 11, 2020 08:24
Show Gist options
  • Save sharpobject/1a119447c15a3daa3933531f320a269d to your computer and use it in GitHub Desktop.
Save sharpobject/1a119447c15a3daa3933531f320a269d to your computer and use it in GitHub Desktop.
luajit 2.1.0-beta3 segfault :(
local function arr_to_set(t)
local ret = {}
for k,v in ipairs(t) do
ret[v] = true
end
return ret
end
local check_31 = arr_to_set{1,13,17,29,37,41,49,53}
local check_32 = arr_to_set{7,19,31,43}
local check_33 = arr_to_set{11,23,47,59}
local function get_primes(lim)
local t = {2,3,5}
local sv = {}
--for i=1,lim do
-- sv[i] = false
--end
for x=1,lim do
if x % 2 == 1 then print("loop 1 x "..x) end
local nx = 4*x*x
if nx > lim then
goto break1
end
for y=1,lim,2 do
local n = nx + y*y
if n > lim then
goto continue1
end
if check_31[n % 60] then
sv[n] = not sv[n]
end
end
::continue1::
end
::break1::
for x=2,lim do
if x % 10000 == 1 then print("loop 2 x "..x) end
local nx = 3*x*x
if nx > lim then
goto break3
end
for y=1,lim,2 do
local n = nx + y*y
if n > lim then
goto continue2
end
if check_33[n % 60] then
sv[n] = not sv[n]
end
end
::continue2::
end
::break2::
for x=1,lim do
if x % 10000 == 1 then print("loop 3 x "..x) end
local nx = 3*x*x
if nx - (x-1) * (x-1) > lim then
goto break3
end
for y=x-1,1,-2 do
local n = nx - y*y
if n > lim then
goto continue3
end
if check_33[n % 60] then
sv[n] = not sv[n]
end
end
::continue3::
end
::break3::
end
get_primes(2000000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment