Odd and square numbers: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
(Added Vala) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(6 intermediate revisions by 4 users not shown) | |||
Line 392:
Same algorithm as the Algol and other samples.
<br>Note formatted output is not Euler's strong point...
'''begin'''▼
<syntaxhighlight lang="euler">▼
'''new''' toNext; '''new''' oddSquare; '''label''' again;▼
▲begin
▲ new toNext; new oddSquare; label again;
toNext <- 0;
again:▼
'''if''' oddSquare < 1000 '''then''' '''begin'''
▲again:
'''if''' oddSquare
'''end''' '''else''' 0▼
▲ end else 0
'''end''' $▼
▲end $
</syntaxhighlight>▼
{{out}}
<pre>
Line 634 ⟶ 632:
841
961
</pre>
=={{header|Lua}}==
for i = 1, math.sqrt( 1000 ), 2 do
local i2 = i * i
if i2 > 99 then
io.write( " ", i2 )
end
end
▲</syntaxhighlight>
{{out}}
<pre>
121 169 225 289 361 441 529 625 729 841 961
</pre>
Line 687 ⟶ 699:
{{out}}<pre>
{121,169,225,289,361,441,529,625,729,841,961}
</pre>
=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
block(
[count:99,odd_square:[]],
while count<1000 do (
i:lambda([x],oddp(x) and integerp(sqrt(x)))(count),
if i then odd_square:endcons(count,odd_square),
count:count+1),
odd_square);
</syntaxhighlight>
{{out}}
<pre>
[121,169,225,289,361,441,529,625,729,841,961]
</pre>
Line 802 ⟶ 829:
=={{header|OCaml}}==
<syntaxhighlight lang="ocaml">let
let rec next n a () = Seq.Cons (n, next (n + a) (a + 8)) in
let () =
seq_odd_squares |> Seq.drop_while ((>) 100) |> Seq.take_while ((>) 1000)
|> Seq.iter (Printf.printf " %u") |> print_newline</syntaxhighlight>
{{out}}<pre> 121 169 225 289 361 441 529 625 729 841 961</pre>
Line 956 ⟶ 983:
<syntaxhighlight lang="python">
import math
szamok = []
limit = 1000
for i in range(1,
num = i*i
if (
szamok.append(num)
Line 970 ⟶ 997:
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961]
</pre>
;By using itertools
<syntaxhighlight lang="python">from itertools import accumulate, count, dropwhile, takewhile
print(*takewhile(lambda x: x<1000, dropwhile(lambda x: x<100, accumulate(count(8, 8), initial=1))))</syntaxhighlight>
{{out}}
<pre>121 169 225 289 361 441 529 625 729 841 961</pre>
=={{header|Quackery}}==
Line 1,083 ⟶ 1,117:
=={{header|RPL}}==
≪ { } 99 999 '''FOR''' j '''IF''' j √ FP NOT
{{out}}
<pre>
Line 1,183 ⟶ 1,217:
{{libheader|Wren-iterate}}
{{libheader|Wren-seq}}
<syntaxhighlight lang="
import "./seq" for Lst
|