Rosetta Code - Abundant odd numbers #140
guaracy
started this conversation in
Show and tell
Replies: 2 comments
-
|
Thanks! Done... included comments and some optimizations. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Should be noted:
PS: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My attempt to solve the "Abundant odd numbers" problem on Rosetta Code.
Feel free to improve it and add the source to Rosetta Code and/or to GitHub under tests/rosetta.
Rebol [ title: "Abundant odd numbers" file: %Abundant_odd_numbers.r3 url: https://rosettacode.org/wiki/Abundant_odd_numbers needs: 3.20.0 ] sum-proper-divisors: function[n][ db: collect [ for div 1 (to-integer sqrt to-decimal n) 1 [ if zero? remainder n div [ keep div keep (n / div) ] ] ] (sum unique sort db) - n ] billion: 1'000'000'000 ix: 1 n: 1 print "The first 25 abundant odd numbers:" forever [ n: n + 2 if prime? n [ continue ] prop-div: sum-proper-divisors n if prop-div <= n [ continue ] case [ ix <= 25 [ print [pad n -5 ":" prop-div] ] ix = 1000 [ print ["1000th abundant odd number:" n ":" prop-div] n: billion + 1 ] n > billion [ print ["First abundant odd number > 1 000 000 000:" n ":" prop-div] break ] ] ++ ix ]Beta Was this translation helpful? Give feedback.
All reactions