aboutsummaryrefslogtreecommitdiff
path: root/challenge-140/abigail/lua/ch-2.lua
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-11-26 13:16:22 +0000
committerGitHub <noreply@github.com>2021-11-26 13:16:22 +0000
commitdf966962c65252efa22bc8b686013c9c1b0f8680 (patch)
tree2cf0b1edf0048ce1058d557b9d6a424e0f6fca2a /challenge-140/abigail/lua/ch-2.lua
parentc58aa139f267a08aee64b3129f854b6e637022b3 (diff)
parent5e0ab324c5a454538d112d0930d0fa15d6c8c4b7 (diff)
downloadperlweeklychallenge-club-df966962c65252efa22bc8b686013c9c1b0f8680.tar.gz
perlweeklychallenge-club-df966962c65252efa22bc8b686013c9c1b0f8680.tar.bz2
perlweeklychallenge-club-df966962c65252efa22bc8b686013c9c1b0f8680.zip
Merge pull request #5283 from Abigail/abigail/week-140
Abigail/week 140
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