Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. def append_and_compress(coin_pairs, coin):
  2.     if not coin_pairs or coin_pairs[-1][0] != coin:
  3.         return coin_pairs + ((coin, 1),)
  4.     else:
  5.         return coin_pairs[:-1] + ((coin_pairs[-1][0], coin_pairs[-1][1] + 1),)
  6.  
  7.  
  8. def change(n, coins, choices):
  9.     if n == 0:
  10.         print(coins)
  11.     elif n > 0 and choices:
  12.         change(n - choices[0], append_and_compress(coins, choices[0]), choices)
  13.         change(n, coins, choices[1:])
  14.  
  15.  
  16. def main():
  17.     change(7, (), (50, 20, 15, 10, 5, 3, 2, 1))
  18.  
  19.  
  20. if __name__ == '__main__':
  21.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement