Odd and square numbers: Difference between revisions
Content added Content deleted
(Added Vala) |
(→Python: short alternative) |
||
Line 956: | Line 956: | ||
<syntaxhighlight lang="python"> |
<syntaxhighlight lang="python"> |
||
import math |
import math |
||
szamok=[] |
szamok = [] |
||
limit = 1000 |
limit = 1000 |
||
for i in range(1, |
for i in range(1, math.isqrt(limit - 1) + 1, 2): |
||
num = i*i |
num = i*i |
||
if ( |
if (num > 99): |
||
szamok.append(num) |
szamok.append(num) |
||
Line 970: | Line 970: | ||
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961] |
[121, 169, 225, 289, 361, 441, 529, 625, 729, 841, 961] |
||
</pre> |
</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}}== |
=={{header|Quackery}}== |