Isqrt (integer square root) of X: Difference between revisions
Content added Content deleted
(→{{header|Arturo}}: marked as incorrect, the integer sqrt root used isn't using the method as required by the task (the pseudo-code that uses a quadratic residue).) |
Drkameleon (talk | contribs) (fixed example to correctly implement integer square roots) |
||
Line 286: | Line 286: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
{{incorrect|MAD| <br><br> The algorithm used is not the one that is mandated to be used by the task's requirements: <br><br> finding the integer square root by using a <u>quadratic residue</u> method (as shown my the pseudo-code). <br><br>}} |
|||
<lang rebol>commatize: function [x][ |
<lang rebol>commatize: function [x][ |
||
Line 293: | Line 291: | ||
] |
] |
||
isqrt: function [x][ |
|||
⚫ | |||
num: new x |
|||
q: new 1 |
|||
r: new 0 |
|||
while [q =< num]-> shl.safe 'q 2 |
|||
while [q > 1][ |
|||
shr 'q 2 |
|||
t: (num-r)-q |
|||
shr 'r 1 |
|||
if t >= 0 [ |
|||
num: t |
|||
r: new r+q |
|||
] |
|||
] |
|||
return r |
|||
] |
|||
⚫ | |||
loop range 1 .step: 2 72 'n -> |
loop range 1 .step: 2 72 'n -> |
||
print [n "\t" commatize |
print [n "\t" commatize isqrt 7^n]</lang> |
||
{{out}} |
{{out}} |