1 Replies - 1502 Views - Last Post: 29 December 2011 - 04:36 PM

#1 atik97   User is offline

  • ???
  • member icon

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

Permutation

Posted 22 March 2009 - 02:53 PM

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

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


Is This A Good Question/Topic? 0
  • +

Replies To: Permutation

#2 Karel-Lodewijk   User is offline

  • D.I.C Addict
  • member icon

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

Re: Permutation

Posted 29 December 2011 - 04:36 PM

This snippet calculates the number of permutations rather than generating them. The ruby array has a permutation block function that does generate them if you were looking for that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1