Find square difference: Difference between revisions

Content added Content deleted
(→‎OCaml: add)
Line 77: Line 77:


=={{header|Arturo}}==
=={{header|Arturo}}==

<syntaxhighlight lang="rebol">i: new 1
<syntaxhighlight lang="rebol">i: new 1
while ø [
while ø [
Line 122: Line 121:
501
501
</pre>
</pre>



=={{header|BASIC}}==
=={{header|BASIC}}==
Line 279: Line 277:
501
501
</pre>
</pre>

=={{header|Factor}}==
=={{header|Factor}}==
The difference between squares is the odd numbers, so ls(n)=&#8968;n/2+1&#8969;.
The difference between squares is the odd numbers, so ls(n)=&#8968;n/2+1&#8969;.
Line 381: Line 380:
501
501
</syntaxhighlight>
</syntaxhighlight>

=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let calculate x =
succ (succ x lsr 1)

let () =
Printf.printf "%u\n" (calculate 1000)</syntaxhighlight>
{{out}}
<pre>501</pre>


=={{header|Pari/GP}}==
=={{header|Pari/GP}}==
Line 591: Line 599:


=={{header|Quackery}}==
=={{header|Quackery}}==

<syntaxhighlight lang="quackery"> [ dup * ] is squared ( n --> n )
<syntaxhighlight lang="quackery"> [ dup * ] is squared ( n --> n )
Line 606: Line 613:


==={{header|Using algebra}}===
==={{header|Using algebra}}===

Noting that a²-b² ≡ (a+b)(a-b), and that in this instance a = b+1.
Noting that a²-b² ≡ (a+b)(a-b), and that in this instance a = b+1.