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 500 characters in body
Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Julia 0.6, 16 bytes

!x=x⋅x∈2x.*x

Try it online!

How it works

Let x = [a, b, c].

x⋅x is the dot product of x and itself, so it yields a2 + b2 + c2.

2x.*x is the element-wise product of 2x and x, so it yields [2a2, 2b2, 2c2].

Finally, tests if the integer a2 + b2 + c2 belongs to the vector [2a2, 2b2, 2c2], which is true iff
a2 + b2 + c2 = 2a2 or a2 + b2 + c2 = 2b2 or a2 + b2 + c2 = 2c2, which itself is true iff
b2 + c2 = a2 or a2 + c2 = b2 or a2 + b2 = c2.

Julia 0.6, 16 bytes

!x=x⋅x∈2x.*x

Try it online!

Julia 0.6, 16 bytes

!x=x⋅x∈2x.*x

Try it online!

How it works

Let x = [a, b, c].

x⋅x is the dot product of x and itself, so it yields a2 + b2 + c2.

2x.*x is the element-wise product of 2x and x, so it yields [2a2, 2b2, 2c2].

Finally, tests if the integer a2 + b2 + c2 belongs to the vector [2a2, 2b2, 2c2], which is true iff
a2 + b2 + c2 = 2a2 or a2 + b2 + c2 = 2b2 or a2 + b2 + c2 = 2c2, which itself is true iff
b2 + c2 = a2 or a2 + c2 = b2 or a2 + b2 = c2.

Source Link
Dennis
  • 211.7k
  • 41
  • 380
  • 830

Julia 0.6, 16 bytes

!x=x⋅x∈2x.*x

Try it online!

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