Sequence of non-squares: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Replaced "round.int" by "toInt". Simplified "issqr". Replaced "proc" by "func". Improved output.) |
||
Line 1,609: | Line 1,609: | ||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
<lang nim>import math |
<lang nim>import math, strutils |
||
func nosqr(n: int): seq[int] = |
|||
result = newSeq[int] |
result = newSeq[int](n) |
||
for i in 1..n: |
for i in 1..n: |
||
result[i - 1] = i + i.float.sqrt. |
result[i - 1] = i + i.float.sqrt.toInt |
||
⚫ | |||
sqrt(float(n)).splitDecimal().floatpart < 1e-7 |
|||
⚫ | |||
echo "Sequence for n = 22:" |
|||
let sqr = sqrt(float(n)) |
|||
echo nosqr(22).join(" ") |
|||
let err = abs(sqr - float(round(sqr))) |
|||
err < 1e-7 |
|||
for i in nosqr(1_000_000 - 1): |
|||
⚫ | |||
for i in nosqr(1_000_000): |
|||
echo "\nNo squares were found for n less than 1_000_000."</lang> |
|||
⚫ | |||
{{out}} |
{{out}} |
||
<pre>@[2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27]</pre> |
<pre>@[2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27]</pre> |