Skip to content

Instantly share code, notes, and snippets.

@sujayy1983
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujayy1983/c642751315ccd5abd1b1 to your computer and use it in GitHub Desktop.
Save sujayy1983/c642751315ccd5abd1b1 to your computer and use it in GitHub Desktop.
Given a value in cents. Find the corresponding combinations in which that money maybe paid.
"""
@Author Sujayyendhiren ramarao srinivasamurthi
@Description For a given value find denominations in cents
"""
lDenom = [ 100 ,50, 25, 10, 5 ,1 ]
lDepth = [ '', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t']
def combinations ( num , depth ):
for denom in lDenom[depth:6]:
if( depth == 0 ):
print ""
if( num % denom == 0 ):
print ( lDepth[depth] + str(num/denom) + " * " + str(denom) )
else:
if( num/denom != 0 ):
print lDepth[depth] + str(num/denom) + " * " + str(denom)
combinations( num%denom , depth+1)
if __name__ == '__main__':
combinations( 123, 0 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment