Post History
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 ...
Answer
#2: Post edited
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
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>