aboutsummaryrefslogtreecommitdiff
path: root/challenge-171/deadmarshal/lua/ch-1.lua
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2022-06-30 22:44:10 +0100
committerdrbaggy <js5@sanger.ac.uk>2022-06-30 22:44:10 +0100
commitf70fdfee84f602971a4c6c144635883960f2c54f (patch)
tree4884421464be2b25e10dfac958d9fafc39e1b319 /challenge-171/deadmarshal/lua/ch-1.lua
parent58f5e220ae958fe48453e45fedc079df6b466d54 (diff)
parent7755a024f5e0ed7581cce5bdaf7d1156e83fe076 (diff)
downloadperlweeklychallenge-club-f70fdfee84f602971a4c6c144635883960f2c54f.tar.gz
perlweeklychallenge-club-f70fdfee84f602971a4c6c144635883960f2c54f.tar.bz2
perlweeklychallenge-club-f70fdfee84f602971a4c6c144635883960f2c54f.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-171/deadmarshal/lua/ch-1.lua')
-rw-r--r--challenge-171/deadmarshal/lua/ch-1.lua30
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-171/deadmarshal/lua/ch-1.lua b/challenge-171/deadmarshal/lua/ch-1.lua
new file mode 100644
index 0000000000..fa400501ce
--- /dev/null
+++ b/challenge-171/deadmarshal/lua/ch-1.lua
@@ -0,0 +1,30 @@
+local function divisors_sum(n)
+ assert(type(n) == 'number', 'n must be a number!')
+ if n < 2 then return 0 end
+ local sqrt, sum = math.sqrt(n), 0
+ for i = 2, sqrt do
+ if n % i == 0 then
+ sum = sum + i
+ if i ~= sqrt then sum = sum + (n // i) end
+ end
+ end
+ sum = sum + 1
+ return sum
+end
+
+local function abundant_odd_numbers()
+ local t,i = {},1
+ repeat
+ if divisors_sum(i) > i and
+ (i % 2) ~= 0 then
+ t[#t+1] = i
+ end
+ i = i + 1
+ until #t == 20
+ return t
+end
+
+local t = abundant_odd_numbers()
+for i=1, #t do
+ io.write(t[i], ' ')
+end