summaryrefslogtreecommitdiffstats
path: root/10.lua
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2009-05-13 23:32:40 -0500
committerJesse Luehrs <doy@tozt.net>2009-05-13 23:32:40 -0500
commit7e7b56db42ceb8d2b8973eae678fa4b58d5d3659 (patch)
tree7a5cb816809d632e30227c1e39485ed63b500e80 /10.lua
downloadprojecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.tar.gz
projecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.zip
add old solutions
Diffstat (limited to '10.lua')
-rw-r--r--10.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/10.lua b/10.lua
new file mode 100644
index 0000000..cca16c1
--- /dev/null
+++ b/10.lua
@@ -0,0 +1,21 @@
+function isprime(n)
+ if n < 2 then return false end
+ if n == 2 then return true end
+ if math.fmod(n, 2) == 0 then return false end
+ for i = 3, math.ceil(math.sqrt(n)), 2 do
+ if math.fmod(n, i) == 0 then return false end
+ end
+ return true
+end
+
+local i = 3
+local sum = 2
+while true do
+ if i >= 1000000 then break end
+ if isprime(i) then
+ if sum + i < sum then print("overflow") end
+ sum = sum + i
+ end
+ i = i + 2
+end
+print(sum)