Last active
August 29, 2015 14:17
-
-
Save anupamkumar/818f94c570a9a5419f1c to your computer and use it in GitHub Desktop.
NumberOfWaysToReachScore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def numOfWaysToTgt(target,allowedUnits) | |
scores = Array.new(target+1,0) | |
scores[0] = 1 | |
allowedUnits.each do |allowedScore| | |
(allowedScore..target).each do |k| | |
scores[k] += scores[k-allowedScore] | |
end | |
end | |
puts "#{target} can be reached in #{scores[target]} ways" | |
end | |
numOfWaysToTgt(20,[3,5,10]) | |
numOfWaysToTgt(13,[3,5,10]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment