Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges It's Hip to be Square

Python 3, 46 bytes Saved 8 bytes thanks to Shaggy! lambda n:[n-i*i or exit(1)for i in range(1+n)] Try it online! Python 3.8 (pre-release), 50 54 52 bytes Fixed a silly mistake thanks to Sh...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#4: Post edited by user avatar user‭ · 2021-09-15T21:15:08Z (over 3 years ago)
  • # [Python 3.8 (pre-release)], <s>50</s> <s>54</s> 52 bytes
  • Fixed a silly mistake thanks to Shaggy *and* saved 2 bytes!
  • <!-- language-all: lang-python -->
  • for i in range(1+(x:=int(input()))):x-i*i or exit(1)
  • [Try it online!][TIO-ktkpylgb]
  • [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
  • [TIO-ktkpylgb]: https://tio.run/##K6gsycjPM7YoKPr/Py2/SCFTITNPoSgxLz1Vw1Bbo8LKNjOvRCMzr6C0REMTCKwqdDO1MhWAClMrMks0DDX//zcAAA "Python 3.8 (pre-release) – Try It Online"
  • Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).
  • # [Python 3], 46 bytes
  • Saved 8 bytes thanks to [Shaggy](https://codegolf.codidact.com/users/53588)!
  • <!-- language-all: lang-python -->
  • lambda n:[n-i*i or exit(1)for i in range(1+n)]
  • [Try it online!][TIO-ktm050z7]
  • [Python 3]: https://docs.python.org/3/
  • [TIO-ktm050z7]: https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHPKjpPN1MrUyG/SCG1IrNEw1AzDcjMVMjMUyhKzEtP1TDUztOM/Z@mYaD5HwA "Python 3 – Try It Online"
  • # [Python 3.8 (pre-release)], <s>50</s> <s>54</s> 52 bytes
  • Fixed a silly mistake thanks to Shaggy *and* saved 2 bytes!
  • <!-- language-all: lang-python -->
  • for i in range(1+(x:=int(input()))):x-i*i or exit(1)
  • [Try it online!][TIO-ktkpylgb]
  • [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
  • [TIO-ktkpylgb]: https://tio.run/##K6gsycjPM7YoKPr/Py2/SCFTITNPoSgxLz1Vw1Bbo8LKNjOvRCMzr6C0REMTCKwqdDO1MhWAClMrMks0DDX//zcAAA "Python 3.8 (pre-release) – Try It Online"
  • Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).
#3: Post edited by user avatar user‭ · 2021-09-14T23:42:06Z (over 3 years ago)
  • # [Python 3.8 (pre-release)], <s>50</s> 54 bytes
  • Fixed a silly mistake thanks to Shaggy
  • <!-- language-all: lang-python -->
  • for i in range(1+(x:=int(input()))):x==i*i and exit(1)
  • [Try it online!][TIO-ktkm64vz]
  • [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
  • [TIO-ktkm64vz]: https://tio.run/##DcExCoAwDAXQq2RMdbG4SKGHKVjrX9JSIsTTR98br95d9mNM96tPAkFoFmmV48qWMkQZMh7l8EuWMxZQkZOqQTkG9@0D "Python 3.8 (pre-release) – Try It Online"
  • Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).
  • # [Python 3.8 (pre-release)], <s>50</s> <s>54</s> 52 bytes
  • Fixed a silly mistake thanks to Shaggy *and* saved 2 bytes!
  • <!-- language-all: lang-python -->
  • for i in range(1+(x:=int(input()))):x-i*i or exit(1)
  • [Try it online!][TIO-ktkpylgb]
  • [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
  • [TIO-ktkpylgb]: https://tio.run/##K6gsycjPM7YoKPr/Py2/SCFTITNPoSgxLz1Vw1Bbo8LKNjOvRCMzr6C0REMTCKwqdDO1MhWAClMrMks0DDX//zcAAA "Python 3.8 (pre-release) – Try It Online"
  • Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).
#2: Post edited by user avatar user‭ · 2021-09-14T21:56:13Z (over 3 years ago)
  • # [Python 3.8 (pre-release)], 50 bytes
  • <!-- language-all: lang-python -->
  • for i in range(x:=int(input())):x==i*i and exit(1)
  • [Try it online!][TIO-ktfvjovl]
  • [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
  • [TIO-ktfvjovl]: https://tio.run/##FcMxCoAwDAXQq2RMnFp0kEIPU7DqX9JSItTTR3zw@mt303Xvw/1sg0BQGkWvyjNlqDG0P8YikmbOWEBFD6oTxlHcYwhh@38 "Python 3.8 (pre-release) – Try It Online"
  • Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).
  • # [Python 3.8 (pre-release)], <s>50</s> 54 bytes
  • Fixed a silly mistake thanks to Shaggy
  • <!-- language-all: lang-python -->
  • for i in range(1+(x:=int(input()))):x==i*i and exit(1)
  • [Try it online!][TIO-ktkm64vz]
  • [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
  • [TIO-ktkm64vz]: https://tio.run/##DcExCoAwDAXQq2RMdbG4SKGHKVjrX9JSIsTTR98br95d9mNM96tPAkFoFmmV48qWMkQZMh7l8EuWMxZQkZOqQTkG9@0D "Python 3.8 (pre-release) – Try It Online"
  • Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).
#1: Initial revision by user avatar user‭ · 2021-09-11T14:19:42Z (over 3 years ago)
# [Python 3.8 (pre-release)], 50 bytes

<!-- language-all: lang-python -->

    for i in range(x:=int(input())):x==i*i and exit(1)

[Try it online!][TIO-ktfvjovl]

[Python 3.8 (pre-release)]: https://docs.python.org/3.8/
[TIO-ktfvjovl]: https://tio.run/##FcMxCoAwDAXQq2RMnFp0kEIPU7DqX9JSItTTR3zw@mt303Xvw/1sg0BQGkWvyjNlqDG0P8YikmbOWEBFD6oTxlHcYwhh@38 "Python 3.8 (pre-release) – Try It Online"

Here's a stupid solution that outputs using the exit code (1 if it's a perfect square, 0 otherwise).