brewersfan1976

count_ways.rb

Jul 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.40 KB | None | 0 0
  1. def countWays(n, k)
  2.     amount = n
  3.     combinations = k
  4.     count = 1
  5.     n = n - 1
  6.    
  7.     while (count < combinations)
  8.           amount = amount * n
  9.           count = count + 1
  10.           n = n - 1
  11.     end
  12.  
  13.     count = combinations - 1
  14.    
  15.     while (count > 1)
  16.           combinations = combinations * count
  17.           count = count - 1
  18.     end
  19.    
  20.     return amount / combinations
  21. end
Advertisement
Add Comment
Please, Sign In to add comment