Last active
August 29, 2015 14:14
-
-
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.
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
""" | |
@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