Skip to content

Instantly share code, notes, and snippets.

@anupamkumar
Last active August 29, 2015 14:17
Show Gist options
  • Save anupamkumar/818f94c570a9a5419f1c to your computer and use it in GitHub Desktop.
Save anupamkumar/818f94c570a9a5419f1c to your computer and use it in GitHub Desktop.
NumberOfWaysToReachScore
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