Collect and sort square numbers in ascending order from three lists: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 507: | Line 507: | ||
</pre> |
</pre> |
||
=={{header|Ruby}}== |
|||
<syntaxhighlight lang="ruby">class Integer |
|||
def square? |
|||
isqrt = Integer.sqrt(self) |
|||
isqrt*isqrt == self |
|||
end |
|||
end |
|||
list = [3,4,34,25,9,12,36,56,36].chain( |
|||
[2,8,81,169,34,55,76,49,7], |
|||
[75,121,75,144,35,16,46,35]) |
|||
p list.select(&:square?).sort |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>[4, 9, 16, 25, 36, 36, 49, 81, 121, 144, 169] |
|||
</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">var lists = [ |
<syntaxhighlight lang="ruby">var lists = [ |