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?

Parent

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)
Post
+1
−0

Python 3, 235 185 141 118 bytes

a=[[],[],[]]
n=1;exec("d=sum(i for i in range(1,n)if n%i<1)-n;a[[[1,2][d<0],0][d>0]]+=n,;n+=1;"*int(input()))
print(a)

Try it online!

Golfed 50 bytes by @caird coinheringaahing. Golfed 44 bytes by @bastolki. Golfed another 23 bytes by @bastolki.

History
Why does this post require moderator attention?
You might want to add some details to your flag.

2 comment threads

[141 bytes](https://tio.run/##TY2xCsMgFEVn/QqXgI@4SLvUxvxIyaDGtA/aFzFm6NfbWCh0OdwDB256l8dKp1q9vU3X0OA... (2 comments)
General comments (1 comment)
[141 bytes](https://tio.run/##TY2xCsMgFEVn/QqXgI@4SLvUxvxIyaDGtA/aFzFm6NfbWCh0OdwDB256l8dKp1q9vU3X0OA...
bastolski‭ wrote over 2 years ago · edited over 2 years ago
bastolski‭ wrote over 2 years ago