aboutsummaryrefslogtreecommitdiff
path: root/challenge-140/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-140/abigail/lua/ch-2.lua')
-rw-r--r--challenge-140/abigail/lua/ch-2.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-140/abigail/lua/ch-2.lua b/challenge-140/abigail/lua/ch-2.lua
new file mode 100644
index 0000000000..601fc35041
--- /dev/null
+++ b/challenge-140/abigail/lua/ch-2.lua
@@ -0,0 +1,30 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-2.lua < input-file
+--
+
+for line in io . lines () do
+ local _, _, i, j, k = line : find ("([0-9]+)%s+([0-9]+)%s+([0-9]+)")
+ i = tonumber (i)
+ j = tonumber (j)
+ k = tonumber (k)
+
+ local n = 0
+ while k > 0 do
+ n = n + 1
+ local s = math . floor (math . sqrt (n))
+ for d = 1, s do
+ if n % d == 0 then
+ if d <= i and n / d <= j then k = k - 1 end
+ if d <= j and n / d <= i then k = k - 1 end
+ if n == d * d then k = k + 1 end
+ end
+ end
+ end
+ print (n)
+end