Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Are they abundant, deficient or perfect?

Post

Are they abundant, deficient or perfect?

+5
−0

Abundant numbers are numbers which are less than their proper divisor sum. For example $18$ is abundant as $1 + 2 + 3 + 6 + 9 = 21 > 18$

Deficient numbers are numbers which are greater than their proper divisor sum. For example, $15$ is deficient as $1 + 3 + 5 = 9 < 15$

Perfect numbers are numbers wich are equal to their proper divisor sum. For example, $6$ is perfect as $1 + 2 + 3 = 6$.

You should take a positive integer $x \ge 12$ and output three lists. The lists should contain, in any order, the abundant numbers less than or equal to $x$, the deficient numbers less than or equal to $x$ and the perfect numbers less than or equal to $x$.

For example, if $x = 15$, the output could look like

[[12], [6], [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15]]

This is code golf, so the shortest code in bytes wins

Test cases

49 -> [[12, 18, 20, 24, 30, 36, 40, 42, 48], [6, 28], [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 29, 31, 32, 33, 34, 35, 37, 38, 39, 41, 43, 44, 45, 46, 47, 49]]
32 -> [[12, 18, 20, 24, 30], [6, 28], [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 29, 31, 32]]
16 -> [[12], [6], [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16]]
29 -> [[12, 18, 20, 24], [6, 28], [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 29]]
23 -> [[12, 18, 20], [6], [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23]]
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

General comments (6 comments)
General comments
caird coinheringaahing‭ wrote almost 3 years ago

Brownie points for beating or matching my 6 byte Jelly answer

Monica Cellio‭ wrote almost 3 years ago

In the text you say to output abundant, deficient, perfect, but your examples look like deficient and perfect are swapped. It doesn't seem to matter for length of code and I assume the examples are what matter?

caird coinheringaahing‭ wrote almost 3 years ago

@MonicaCellio The examples are just that - examples. You're free to output the three lists in any order (and the elements in those lists in any order), so long as there is a clear distinction between the lists themselves and between the elements in the lists

Monica Cellio‭ wrote almost 3 years ago

Ah, ok -- I parsed the "in any order" as being for the elements within each list, so I was a little confused. Thanks for clarifying.

General Sebast1an‭ wrote almost 3 years ago

I might be taking the output literally, but is it okay/required to add the bracket at the beginning and end of the output?

caird coinheringaahing‭ wrote almost 3 years ago

@DerrickWilliams Any format that clearly distinguishes the output is fine - the format I've used is not required