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 103 characters in body
Source Link
mathmandan
  • 1k
  • 11
  • 10

Python 3, (削除) 40 (削除ここまで) 38 bytes

Thanks to squid for saving 2 bytes!

lambda n:n in[i*iin(i*i for i in range(n+1)])

Try it online! Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time. (But written using a generator to save memory, but would work given sufficient timesince it doesn't cost any bytes.)

(This works Works in Python 2 also, but note that Python 2 will yieldthough an OverflowError on very largeis a possibility due to range if you try it with huge inputs. (A MemoryError would also be likely in Python 2, also due to range.)

Python 3, (削除) 40 (削除ここまで) 38 bytes

Thanks to squid for saving 2 bytes!

lambda n:n in[i*i for i in range(n+1)]

Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time, but would work given sufficient time.

(This works in Python 2 also, but note that Python 2 will yield an OverflowError on very large inputs, due to range.)

Python 3, (削除) 40 (削除ここまで) 38 bytes

Thanks to squid for saving 2 bytes!

lambda n:n in(i*i for i in range(n+1))

Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time. (But written using a generator to save memory, since it doesn't cost any bytes.)

Works in Python 2 also, though an OverflowError is a possibility due to range if you try it with huge inputs. (A MemoryError would also be likely in Python 2, also due to range.)

added 53 characters in body
Source Link
mathmandan
  • 1k
  • 11
  • 10

Python 3, 40(削除) 40 (削除ここまで) 38 bytes

Thanks to squid for saving 2 bytes!

lambda n:any(i*i==nn in[i*i for i in range(n+1))]

Try it online! Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time, but would work given sufficient time.

(This works in Python 2 also, but note that Python 2 will yield an OverflowError on very large inputs, due to range.)

Python 3, 40 bytes

lambda n:any(i*i==n for i in range(n+1))

Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time, but would work given sufficient time.

(This works in Python 2 also, but note that Python 2 will yield an OverflowError on very large inputs, due to range.)

Python 3, (削除) 40 (削除ここまで) 38 bytes

Thanks to squid for saving 2 bytes!

lambda n:n in[i*i for i in range(n+1)]

Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time, but would work given sufficient time.

(This works in Python 2 also, but note that Python 2 will yield an OverflowError on very large inputs, due to range.)

Source Link
mathmandan
  • 1k
  • 11
  • 10

Python 3, 40 bytes

lambda n:any(i*i==n for i in range(n+1))

Try it online!

Too slow to return an answer for 2147483647 in a reasonable amount of time, but would work given sufficient time.

(This works in Python 2 also, but note that Python 2 will yield an OverflowError on very large inputs, due to range.)

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