Collect and sort square numbers in ascending order from three lists: Difference between revisions
Collect and sort square numbers in ascending order from three lists (view source)
Revision as of 13:30, 4 December 2022
, 1 year ago→{{header|Ruby}}: Add Ruby
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(→{{header|Ruby}}: Add Ruby) |
||
Line 507:
</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}}==
<syntaxhighlight lang="ruby">var lists = [
|