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

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

Embed ESCR, 28 characters [= [exp [rnd [sqrt n]] 2] n] The number to test is in N. There are 4 nested functions. From inner to outer: SQRT takes the square root of N. This produces a floating ...

posted 2y ago by Olin Lathrop‭  ·  edited 2y ago by Olin Lathrop‭

Answer
#2: Post edited by user avatar Olin Lathrop‭ · 2022-02-11T19:00:11Z (about 2 years ago)
  • Embed <a href="http://www.embedinc.com/pic/escr">ESCR</a>, 28 characters
  • <pre>[= [exp [rnd [sqrt n]] 2] n]</pre>
  • The number to test is in N. There are 4 nested functions. From inner to outer: SQRT takes the square root of N. This produces a floating point result. RND rounds that to the nearest integer. EXP is used to raise that integer to the power of 2 (square it). This produces an integer since both inputs are integers. "=" compares the squared result to N. The result is a boolean value, which is either "TRUE" or "FALSE" in its text representation.
  • Here is a complete program illustrating the above applied to input values 0 to 20:
  • <pre>loop with n from 0 to 20
  • show n ": " [= [exp [rnd [sqrt n]] 2] n]
  • endloop</pre>
  • Its output is:
  • <pre>0: TRUE
  • 1: TRUE
  • 2: FALSE
  • 3: FALSE
  • 4: TRUE
  • 5: FALSE
  • 6: FALSE
  • 7: FALSE
  • 8: FALSE
  • 9: TRUE
  • 10: FALSE
  • 11: FALSE
  • 12: FALSE
  • 13: FALSE
  • 14: FALSE
  • 15: FALSE
  • 16: TRUE
  • 17: FALSE
  • 18: FALSE
  • 19: FALSE
  • 20: FALSE</pre>
  • <h2>Embed <a href="http://www.embedinc.com/pic/escr">ESCR</a>, 28 characters</h2>
  • <pre>[= [exp [rnd [sqrt n]] 2] n]</pre>
  • The number to test is in N. There are 4 nested functions. From inner to outer: SQRT takes the square root of N. This produces a floating point result. RND rounds that to the nearest integer. EXP is used to raise that integer to the power of 2 (square it). This produces an integer since both inputs are integers. "=" compares the squared result to N. The result is a boolean value, which is either "TRUE" or "FALSE" in its text representation.
  • Here is a complete program illustrating the above applied to input values 0 to 20:
  • <pre>loop with n from 0 to 20
  • show n ": " [= [exp [rnd [sqrt n]] 2] n]
  • endloop</pre>
  • Its output is:
  • <pre>0: TRUE
  • 1: TRUE
  • 2: FALSE
  • 3: FALSE
  • 4: TRUE
  • 5: FALSE
  • 6: FALSE
  • 7: FALSE
  • 8: FALSE
  • 9: TRUE
  • 10: FALSE
  • 11: FALSE
  • 12: FALSE
  • 13: FALSE
  • 14: FALSE
  • 15: FALSE
  • 16: TRUE
  • 17: FALSE
  • 18: FALSE
  • 19: FALSE
  • 20: FALSE</pre>
#1: Initial revision by user avatar Olin Lathrop‭ · 2022-02-11T17:19:55Z (about 2 years ago)
Embed <a href="http://www.embedinc.com/pic/escr">ESCR</a>, 28 characters

<pre>[= [exp [rnd [sqrt n]] 2] n]</pre>

The number to test is in N.  There are 4 nested functions.  From inner to outer: SQRT takes the square root of N.  This produces a floating point result.  RND rounds that to the nearest integer.  EXP is used to raise that integer to the power of 2 (square it).  This produces an integer since both inputs are integers.  "=" compares the squared result to N.  The result is a boolean value, which is either "TRUE" or "FALSE" in its text representation.

Here is a complete program illustrating the above applied to input values 0 to 20:

<pre>loop with n from 0 to 20
  show n ": " [= [exp [rnd [sqrt n]] 2] n]
  endloop</pre>

Its output is:

<pre>0: TRUE
1: TRUE
2: FALSE
3: FALSE
4: TRUE
5: FALSE
6: FALSE
7: FALSE
8: FALSE
9: TRUE
10: FALSE
11: FALSE
12: FALSE
13: FALSE
14: FALSE
15: FALSE
16: TRUE
17: FALSE
18: FALSE
19: FALSE
20: FALSE</pre>