Created
September 8, 2020 15:15
-
-
Save sadimanna/36edbb7e3c01ec70e4806be7bf35f1cf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import sympy as sp | |
| if __name__ == '__main__': | |
| stime = time.time() | |
| denominations = [1,2,5,10,20,50,100,200] | |
| maxpowers = [200//d for d in denominations] | |
| x = sp.symbols('x') | |
| expr_dict = {} | |
| for i in range(len(denominations)): | |
| power = maxpowers[i] | |
| expr_dict[denominations[i]] = 1 | |
| for p in range(1,power+1): | |
| expr_dict[denominations[i]] += x**(p*denominations[i]) | |
| GF = 1 | |
| for i in range(len(denominations)): | |
| GF *= expr_dict[list(expr_dict.keys())[i]] | |
| GF = sp.expand(GF) | |
| print("Number of ways = Co-efficient of x**200 in the Generating Function : %d"%(GF.coeff(x,200))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment