Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 46 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

True for perfect; False for others (switch this with == -> !=)

Try it online!

44(削除) 44 42 (削除ここまで) 41 bytes (-2 thanks to ovs) if we may output using "truthy vs falsey":

f=lambda n,i=1:i/n or-~f(n,i+1)-(n%i<1)*i

(falsey (0)) for perfect,perfect; truthy (nona non-zero integer) otherwise):

lambda n:sum(d*(n%d<1)for d in range(1,n))-n

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

True for perfect; False for others (switch this with == -> !=)

Try it online!

44 bytes if we may output using "truthy vs falsey"(falsey (0) for perfect, truthy (non-zero integer) otherwise):

lambda n:sum(d*(n%d<1)for d in range(1,n))-n

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

True for perfect; False for others (switch this with == -> !=)

Try it online!

(削除) 44 42 (削除ここまで) 41 bytes (-2 thanks to ovs) if we may output using "truthy vs falsey":

f=lambda n,i=1:i/n or-~f(n,i+1)-(n%i<1)*i

(falsey (0)) for perfect; truthy (a non-zero integer) otherwise

added 111 characters in body
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

True for perfect; False for others (switch this with == -> !=)

Try it online!

44 bytes if we may output using "truthy vs falsey" (falsey (0) for perfect, truthy (non-zero integer) otherwise):

lambda n:sum(d*(n%d<1)for d in range(1,n))-n

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

Try it online!

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

True for perfect; False for others (switch this with == -> !=)

Try it online!

44 bytes if we may output using "truthy vs falsey" (falsey (0) for perfect, truthy (non-zero integer) otherwise):

lambda n:sum(d*(n%d<1)for d in range(1,n))-n
Source Link
Jonathan Allan
  • 115.4k
  • 8
  • 68
  • 293

Python, 45 bytes

lambda n:sum(d*(n%d<1)for d in range(1,n))==n

Try it online!

AltStyle によって変換されたページ (->オリジナル) /