aboutsummaryrefslogtreecommitdiff
path: root/challenge-109/abigail/lua/ch-1.lua
diff options
context:
space:
mode:
author冯昶 <seaker@qq.com>2021-04-26 14:38:42 +0800
committer冯昶 <seaker@qq.com>2021-04-26 14:38:42 +0800
commit8e8759a0d1ac0cb3c7e329b52fd3a242eb1781f7 (patch)
tree124e60bc8400206b1b5bd31e5a821e3e8c5f026d /challenge-109/abigail/lua/ch-1.lua
parentaf66a71f6313aa7102dff899c27ea0958e0b83d2 (diff)
parent1ff197d81f941c3dd35d77bec8a0326807e8d2b1 (diff)
downloadperlweeklychallenge-club-8e8759a0d1ac0cb3c7e329b52fd3a242eb1781f7.tar.gz
perlweeklychallenge-club-8e8759a0d1ac0cb3c7e329b52fd3a242eb1781f7.tar.bz2
perlweeklychallenge-club-8e8759a0d1ac0cb3c7e329b52fd3a242eb1781f7.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-109/abigail/lua/ch-1.lua')
-rw-r--r--challenge-109/abigail/lua/ch-1.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-109/abigail/lua/ch-1.lua b/challenge-109/abigail/lua/ch-1.lua
new file mode 100644
index 0000000000..74c3b7d914
--- /dev/null
+++ b/challenge-109/abigail/lua/ch-1.lua
@@ -0,0 +1,43 @@
+#!/opt/local/bin/lua
+
+--
+-- See ../README.md
+--
+
+--
+-- Run as: lua ch-1.lua [plain | compute]
+--
+
+local PLAIN = 0
+local COMPUTE = 1
+
+local COUNT = 20
+
+function divisor_sum (n)
+ local sum = 0
+ for i = 2, n / 2 do
+ if n % i == 0
+ then sum = sum + i
+ end
+ end
+ return (sum)
+end
+
+local type = PLAIN
+if #arg >= 1 and arg [1] == "compute"
+then type = COMPUTE
+end
+
+if type == PLAIN
+then print ("0, 0, 0, 2, 0, 5, 0, 6, 3, 7, 0, 15, 0, 9, 8, 14, 0, 20, 0, 21")
+end
+
+if type == COMPUTE
+then for n = 1, COUNT do
+ if n > 1
+ then io . write (", ")
+ end
+ io . write (divisor_sum (n))
+ end
+ io . write ("\n")
+end