Add script to calculate primes

This commit is contained in:
Talia 2020-08-27 14:42:50 +02:00
parent 5f1921ef15
commit 4cc5d0ece9
1 changed files with 28 additions and 0 deletions

28
bin/primes Executable file
View File

@ -0,0 +1,28 @@
#!/usr/bin/env luajit
local primes = require 'primes'
local arrr = require 'arrr'
local parse = arrr {
{ "Starting number", "--min", "-m", 1, tonumber };
{ "Last Number", "--max", "-M", 1, tonumber };
{ "Cache file", "--cache", "-c", 1, io.open };
}
local options = parse{...}
local min, max =
options.min or 1,
options.max or math.huge
if options.cache then
local i = 1
for line in options.cache:lines() do
primes[i] = tonumber(line)
i = i + 1
end
end
for i = min, max do
print(primes[i])
end