Challenges

# 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

[, , [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 -> [, , [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], , [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23]]
Why does this post require moderator attention?
Why should this post be closed?

+4
−0

# APL (Dyalog Unicode), 21 bytes

{×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳


Try it online!

Returns a matrix (padded with zeroes) where the first row is deficient numbers, the second is perfect numbers, and the third is abundant numbers.

{×⍵-+/∪⍵∨¯1↓⍳⍵}¨∘⍳⊢⌸⍳
⍳    ⍝ Make a range [1, input]
¨     ⍝ For every ⍵ in that range
⍳⍵       ⍝ Make a range [1, ⍵]
¯1↓         ⍝ Drop the last number (⍵)
⍵∨            ⍝ GCD all numbers in that range with ⍵
∪               ⍝ The previous step gave proper divisors, this removes duplicates
+/                ⍝ Sum proper divisors
⍵-                  ⍝ Subtract from ⍵
×                    ⍝ Get the sign
⍳ ⍝ Make another range [1, input]
⌸  ⍝ Group by the signs of the differences we got earlier

Why does this post require moderator attention?

+4
−0

# Vyxalo, 16 bytes

'∆K=;,'∆K<;,'∆K>


Try it Online!

Checks all numbers to see if they are perfect, then prints the ones that are, then does the same for abundant and deficient numbers.

Explanation:

                  # Implicit input 'n'
'   ;,            # Print any numbers in [1..n] for which the following is true:
∆K=              #   The number = the sum of its proper divisors
'   ;,      # Print any numbers in [1..n] for which the following is true:
∆K<        #   The number < the sum of its proper divisors
'     # Push a list of numbers in [1..n] for which the following is true:
∆K>  #   The number > the sum of its proper divisors
# 'o' flag - Implicit output regardless of having printed

Why does this post require moderator attention?

+4
−0

# Husk, 10 bytes

kSo±-ȯΣhḊḣ


Try it online!

keyon is very nice here, but it's still a bit too long, sadly.

Why does this post require moderator attention?

+3
−0

# Vyxal, 3028 25 bytes

Saved 1 4 bytes thanks to Aaron Miller

ƛ∆K-±";£kɽƛ¥D„£_'t¥=;vṪ,£


Try it Online!

A rather pitiful answer, but hey, it works. Gives deficient numbers, then perfect numbers, then abundant numbers.

ƛD∆K-±$";£ ƛ ; #For every number in the range [1,n] D #Triplicate it ∆K #Sum its proper divisors - #Subtract the original number from that ± #Get the sign of that (-1, 0, or 1)$"   #Make a 2-element list [sign, orig_num]
#Sort it
£ #Store it in the register


For an input of 12, this gives ⟨⟨1|1⟩|⟨1|2⟩|⟨1|3⟩|⟨1|4⟩|⟨1|5⟩|⟨0|6⟩|⟨1|7⟩|⟨1|8⟩|⟨1|9⟩|⟨1|10⟩|⟨1|11⟩|⟨-1|12⟩⟩ (0 means perfect, -1 means deficient, 1 means abundant). The explanation's old.

kɽƛ¥D„£_'h¥=;ƛḢ;,£
kɽ                 #Push [-1, 0, 1]
ƛ                #For every number in that range
¥D              #Make three copies of the register (the list above)
„             #Rotate stack so -1, 0, or 1 is on top
£_           #Store to register temporarily
'   ;      #Filter the list from above
h         #Take the head of each
¥=       #Keep if it equals the current element from [-1,0,1]
ƛḢ;   #Drop the sign from each
,  #Print this list of numbers
£ #Store original list to register again

Why does this post require moderator attention?

+3
−0

# Jelly, 6 bytes

_ÆṣṠ)Ġ


Try it online!

In order of abundant, perfect, deficient.

_ÆṣṠ)Ġ  Main Link
)   For each from 1 to N
_       Subtract
Æṣ     The proper divisor sum
Ṡ    Sign of the difference
Ġ  Group equal elements' indices

Why does this post require moderator attention?

+2
−0

# BQN, 21 bytesSBCS

(¬·×-+´·/0=↕⊸|)¨⊸⊔1+↕


Run online!

Mostly one big train used to find the appropriate group for each number, to be used with Group (⊔). The combining functions in a train normally have two arguments, but Nothing (·) can be used on the left to not pass a left argument. See also Indices (/), and note that Modulus (|) is backwards relative to C-like %.

(¬·×-+´·/0=↕⊸|)¨⊸⊔1+↕
1+↕  # One plus range: 1…𝕩
(             )¨       # On each of these (n):
↕           #   Range 0…n-1
⊸|         #   Remainder dividing into n
0=            #   Equals zero
·/              #   Indices where true: proper divisors
-+´                #   Sum with initial value -n
·×                   #   Sign
¬                     #   One minus that
⊸⊔     # Use to group 1+↕


There might be a better solution based on taking the modulus on all pairs instead of one at a time. (¬·×-+˝(⊣×≠>|)⌜˜)⊸⊔1+↕ is close at 22 bytes.

Why does this post require moderator attention?

+2
−0

# Japt, 11 bytes

õ üÈgXnXâ x


Try it

õ üÈgXnXâ x     :Implicit input of integer U
õ               :Range [0,U]
ü             :Group & sort
È            :By passing each X through the following function
g           :  Sign of difference of X and
Xn         :    Subtract X from
Xâ       :      All divisors of X
x     :      Reduced by addition
Why does this post require moderator attention?

+2
−0

# Python 3, 235 185 bytes

b=;c=[];a=[]
for n in range(2,int(input())+1):
d=1
for i in range(2,int(n**.5)+1):
if n%i<1:
d+=i;j=n//i
if j!=i:d+=j
if d>n:a+=n,
elif d<n:b+=n,
else:c+=n,
print(a,c,b)


Try it online!

-50 by caird coinheringaahing

Why does this post require moderator attention? 