Anonymous user
Sequence of non-squares: Difference between revisions
m
→{{header|REXX}}: added whitespace.
m (→{{header|Python}}: Compacted list display) |
m (→{{header|REXX}}: added whitespace.) |
||
Line 2,100:
say center(j, 20) center(j +floor(1/2 +sqrt(j)), 20)
end /*j*/
#= 0
do k=1 for M /*have it step through a million of 'em*/
$= k + floor( sqrt(k) + .5 ) /*use the specified formula (algorithm)*/
iRoot= iSqrt($)
if iRoot * iRoot == $ then #= # + 1
end /*k*/
say; if #==0 then #= 'no' /*use gooder English for display below.*/
Line 2,111:
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
floor: parse arg floor_;
/*──────────────────────────────────────────────────────────────────────────────────────*/
iSqrt: procedure; parse arg x; #=1;
do while #>1; #=#%4; _=x-r-#; r=r%2; if _<0 then iterate; x=_; r=r+#; end; return r
/*──────────────────────────────────────────────────────────────────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0; d=digits(); m.=9; numeric form; h=d+6
numeric digits; parse value format(x,2,1,,0) 'E0' with g 'E' _ .; g=g *.5'e'_
do j=0 while h>9; m.j= h;
do k=j+5 to 0 by -1; numeric digits m.k; g= (g+x/g)*.5; end /*k*/;
{{out|output}}
<pre>
|