Thomas Preymesser wrote:
> On 25 February 2010 09:40, 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?
>>
> 
> 0 children / 0 men
> 0 children / 1 men
> 0 children / 2 men
> 0 children / 3 men
> 0 children / 4 men
> 1 children / 0 men
> 1 children / 1 men
> 1 children / 2 men
> 1 children / 3 men
> 2 children / 0 men
> 2 children / 1 men
> 2 children / 2 men
> 3 children / 0 men
> 3 children / 1 men

max = 4
@result = []
(0..max).each do |x|
  (0..(max - x)).each do |y|
    @combination = []
    x.times { @combination << "children" }
    y.times { @combination << "men" }
    @result << @combination
  end
end

Thank you very much
> 4 children / 0 men

-- 
Posted via http://www.ruby-forum.com/.