From c3ff98ee4aa79bcaa07c8a478e96539c2a512e73 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 14 May 2009 19:51:41 -0500 Subject: rename files for better sorting --- 012.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 012.lua (limited to '012.lua') diff --git a/012.lua b/012.lua new file mode 100644 index 0000000..7ef1c0d --- /dev/null +++ b/012.lua @@ -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 -- cgit v1.2.3