"Guy N. Hurst" wrote:
> 
> Luigi Ballabio wrote:
> > ...
> > 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)]
> >
> 
> irb(main):006:0> l=[]; (1..5).each{|x| (1..5).each{|y| l<<[x,y] if x+y<5}}
> 1..5
> irb(main):007:0> l
> [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [3, 1]]
> irb(main):008:0>

<plug>Using the enumerable tools on RAA</plug>:

require 'enum/op'
include EnumerableOperator

product((1..5),(1..5)).select {|x,y| x+y<5}

# ==> [[1, 1], [1, 2], [1, 3], [2, 1], [2, 2], [3, 1]]

--
Joel VanderWerf                          California PATH, UC Berkeley
mailto:vjoel / path.berkeley.edu                     Ph. (510) 231-9446
http://www.path.berkeley.edu                       FAX (510) 231-9512