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 805 characters in body
Source Link
Gymhgy
  • 8k
  • 12
  • 35

C# (Visual C# Interactive Compiler), 46 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)^n*2

Returns 0 if perfect, otherwise returns a positive number. I don't know if outputting different types of integers are allowed in place of two distinct truthy and falsy values, and couldn't find any discussion on meta about it. If this is invalid, I will remove it.

Try it online!

C# (Visual C# Interactive Compiler) , (削除) 49 (削除ここまで) 47 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)==n*2

Try it online!

C# (Visual C# Interactive Compiler), (削除) 49 (削除ここまで) 47 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)==n*2

Try it online!

C# (Visual C# Interactive Compiler), 46 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)^n*2

Returns 0 if perfect, otherwise returns a positive number. I don't know if outputting different types of integers are allowed in place of two distinct truthy and falsy values, and couldn't find any discussion on meta about it. If this is invalid, I will remove it.

Try it online!

C# (Visual C# Interactive Compiler) , (削除) 49 (削除ここまで) 47 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)==n*2

Try it online!

added 5 characters in body
Source Link
Gymhgy
  • 8k
  • 12
  • 35

C# (Visual C# Interactive Compiler), 49(削除) 49 (削除ここまで) 47 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?n/x:0)==n*2

Try it online! Try it online!

C# (Visual C# Interactive Compiler), 49 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?n/x:0)==n*2

Try it online!

C# (Visual C# Interactive Compiler), (削除) 49 (削除ここまで) 47 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?x:0)==n*2

Try it online!

Source Link
Gymhgy
  • 8k
  • 12
  • 35

C# (Visual C# Interactive Compiler), 49 bytes

n=>Enumerable.Range(1,n).Sum(x=>n%x<1?n/x:0)==n*2

Try it online!

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