diff options
author | Jesse Luehrs <doy@tozt.net> | 2009-05-13 23:32:40 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2009-05-13 23:32:40 -0500 |
commit | 7e7b56db42ceb8d2b8973eae678fa4b58d5d3659 (patch) | |
tree | 7a5cb816809d632e30227c1e39485ed63b500e80 /12.lua | |
download | projecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.tar.gz projecteuler-7e7b56db42ceb8d2b8973eae678fa4b58d5d3659.zip |
add old solutions
Diffstat (limited to '12.lua')
-rw-r--r-- | 12.lua | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -0,0 +1,31 @@ +-- only valid when n > 1 +function num_factors(n) + local ret = 2 + local test = 2 + local limit = math.sqrt(n) + while test < limit do + if n % test == 0 then + ret = ret + 2 + end + test = test + 1 + end + if limit == math.floor(limit) then ret = ret + 1 end + return ret +end + +generate_triangle = coroutine.wrap(function() + local num = 0 + local add = 1 + while true do + num = num + add + add = add + 1 + coroutine.yield(num) + end +end) + +while true do + local n = generate_triangle() + local nn = num_factors(n) + print(n .. ": " .. nn) + if nn > 500 then break end +end |