Luigi Ballabio <ballabio / mac.com> writes:

[...]

> How about
>  >>> l = [(x,y) for x in range(1,5) for y in range(1,5) if x+y < 5]
>  >>> l
> [(1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (3, 1)]

haskell could be

[ (x,y) | x <- [1..5], y <- [1..5], x+y < 5 ]
filter (\(x,y) -> x+y < 5) $ concat $ map (\x -> map (\y -> (x,y)) [1..5]) [1..5]

ruby would be

(1..5).map{|x| (1..5).map{|y| [x,y] if x+y < 5}}.flatten_once.compact

but i can't find the "flatten_once" function.

class Array
  def flatten_once
    l = []
    each{|l1| l += l1}
    l
  end
end


--
Pixel