Jump to content

Isqrt (integer square root) of X: Difference between revisions

fixed example to correctly implement integer square roots
(→‎{{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).)
(fixed example to correctly implement integer square roots)
Line 286:
 
=={{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 &nbsp;<u>quadratic residue</u>&nbsp; method &nbsp; (as shown my the pseudo-code). <br><br>}}
 
<lang rebol>commatize: function [x][
Line 293 ⟶ 291:
]
 
isqrt: function [x][
print map 0..65 => [sqrt.integer]
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
]
 
print map 0..65 => [sqrt.integerisqrt]
loop range 1 .step: 2 72 'n ->
print [n "\t" commatize sqrt.integerisqrt 7^n]</lang>
 
{{out}}
1,532

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.