1 Replies - 1433 Views - Last Post: 29 December 2011 - 05:12 PM

#1 atik97   User is offline

  • ???
  • member icon

Reputation: 144
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Combination Finder

Posted 21 March 2009 - 11:53 AM

Description:
def factorial(n)
  if n==0
    return 1
  else
    return n*factorial(n-1)
  end
end

def combination(x,y)
  if y>x
    puts "Invalid Input!"
  else
    result=factorial(x)/(factorial(x-y)*factorial(y))
    puts "The combination is "+result.to_s
  end
end


Is This A Good Question/Topic? 0
  • +

Replies To: Combination Finder

#2 Karel-Lodewijk   User is offline

  • D.I.C Addict
  • member icon

Reputation: 454
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: Combination Finder

Posted 29 December 2011 - 05:12 PM

This calculates the number of combinations of size x from set y. The Array class in ruby has a combination functions that will generate combinations.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1