On Thu, Feb 25, 2010 at 2:40 AM, Alexander Antonakakis <alexis / maich.gr>wrote: > Hello all > I would like to find an algorithm to caclulate all options on the > following problem. > Lets suppose we have a room of max capacity of 4 persons. > Which are the combinations of man - child in this room? > some of them will be: > empty room (none inside) > 1 man > 1 child > 2 men > 2 children > 2 men 1 children > 2 men 2 children > . > . > 4 men > 4 children > > I appreciate your help > -- > Posted via http://www.ruby-forum.com/. > > def people_in_room(occupants) for men in 0..occupants for children in 0..occupants - men yield men , children end end end puts "in a room with 4 people, you could occupy it in the following ways:" people_in_room 4 do |men,children| puts "men: #{men} , children: #{children}" end