Sequence of non-squares: Difference between revisions

Content added Content deleted
m (→‎{{header|REXX}}: added whitespace.)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 125: Line 125:
Loop 1000000
Loop 1000000
x := A_Index + floor(0.5 + sqrt(A_Index)), s += x = round(sqrt(x))**2
x := A_Index + floor(0.5 + sqrt(A_Index)), s += x = round(sqrt(x))**2
Msgbox Number of bad squares = %s% ; 0</lang>
Msgbox Number of bad squares = %s% ; 0</lang>


=={{header|AWK}}==
=={{header|AWK}}==
Line 1,280: Line 1,280:


</pre>
</pre>

=={{header|Mathematica}}==
=={{header|Mathematica}}==
<lang Mathematica>nonsq = (# + Floor[0.5 + Sqrt[#]]) &;
<lang Mathematica>nonsq = (# + Floor[0.5 + Sqrt[#]]) &;
Line 1,656: Line 1,657:
{{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>

=={{header|Perl 6}}==

{{works with|Rakudo|2016.07}}
<lang perl6>sub nth-term (Int $n) { $n + round sqrt $n }

# Print the first 22 values of the sequence
say (nth-term $_ for 1 .. 22);

# Check that the first million values of the sequence are indeed non-square
for 1 .. 1_000_000 -> $i {
say "Oops, nth-term($i) is square!" if (sqrt nth-term $i) %% 1;
}</lang>

{{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>


=={{header|Phix}}==
=={{header|Phix}}==
Line 2,081: Line 2,066:
#f
#f
</pre>
</pre>

=={{header|Raku}}==
(formerly Perl 6)

{{works with|Rakudo|2016.07}}
<lang perl6>sub nth-term (Int $n) { $n + round sqrt $n }

# Print the first 22 values of the sequence
say (nth-term $_ for 1 .. 22);

# Check that the first million values of the sequence are indeed non-square
for 1 .. 1_000_000 -> $i {
say "Oops, nth-term($i) is square!" if (sqrt nth-term $i) %% 1;
}</lang>

{{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>


=={{header|REXX}}==
=={{header|REXX}}==
Line 2,420: Line 2,422:
no squares found
no squares found
</pre>
</pre>

=={{header|VBA}}==
=={{header|VBA}}==
<lang vb>
<lang vb>
Line 2,444: Line 2,447:
<pre>values for n in the range 1 to 22 : 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27,
<pre>values for n in the range 1 to 22 : 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27,
0 squares less than 1000000</pre>
0 squares less than 1000000</pre>

=={{header|XLISP}}==
=={{header|XLISP}}==
<lang lisp>(defun non-square (n)
<lang lisp>(defun non-square (n)