List comprehensions: Difference between revisions
→{{header|Ruby}}: illustrate loop-less way
m (→{{header|Stata}}: avoid transposition) |
(→{{header|Ruby}}: illustrate loop-less way) |
||
Line 2,110:
This is the exact same code, except that it now defines Enumerable#flat_map and Array#keep_if when those methods are missing. It now works with older versions of Ruby, like 1.8.6.
Illustrating a way to avoid all loops (but no list comprehensions) :
<lang ruby>n = 20
p (1..n).to_a.combination(3).select{|a,b,c| a*a + b*b == c*c}
</lang>
=={{header|Run BASIC}}==
|