diff options
Diffstat (limited to 'challenge-109/abigail/lua/ch-1.lua')
| -rw-r--r-- | challenge-109/abigail/lua/ch-1.lua | 43 |
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 |
