aboutsummaryrefslogtreecommitdiff
path: root/challenge-109/abigail/lua/ch-1.lua
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-04-25 02:19:22 +0100
committerGitHub <noreply@github.com>2021-04-25 02:19:22 +0100
commit1c59c21ec7e7a43ae44f587a7d279b90a31fbb62 (patch)
tree0040d7355d7e9464ce4515f647b923213d28b076 /challenge-109/abigail/lua/ch-1.lua
parente761d4717321a14d02a3ede087ac6c0c396c155b (diff)
parent078dca365480326018fc5482e7c465a9e77824c4 (diff)
downloadperlweeklychallenge-club-1c59c21ec7e7a43ae44f587a7d279b90a31fbb62.tar.gz
perlweeklychallenge-club-1c59c21ec7e7a43ae44f587a7d279b90a31fbb62.tar.bz2
perlweeklychallenge-club-1c59c21ec7e7a43ae44f587a7d279b90a31fbb62.zip
Merge pull request #3945 from Abigail/abigail/week-109
Abigail/week 109
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