Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scanNumber(n)
- for i = 2, math.floor(n/2) + 1 do
- if n % i == 0 then
- return false
- end
- end
- return true
- end
- function getCurrentNumber()
- local num = 3
- nFile = fs.open("primeIndex", "r")
- if nFile then
- num = tonumber(nFile.readAll())
- end
- nFile.close()
- return num
- end
- function saveCurrentNumber(num)
- nFile = fs.open("primeIndex", "w")
- nFile.write(num)
- nFile.close()
- end
- function addPrime(prime)
- pFile = fs.open("primeList", "a")
- pFile.writeLine(prime)
- pFile.close()
- end
- local number = getCurrentNumber()
- while true do
- saveCurrentNumber()
- if scanNumber(number) then
- addPrime(number)
- print(number)
- end
- number = number + 1
- if number % 50 == 0 then
- sleep(.01)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement