Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def append_and_compress(coin_pairs, coin):
- if not coin_pairs or coin_pairs[-1][0] != coin:
- return coin_pairs + ((coin, 1),)
- else:
- return coin_pairs[:-1] + ((coin_pairs[-1][0], coin_pairs[-1][1] + 1),)
- def change(n, coins, choices):
- if n == 0:
- print(coins)
- elif n > 0 and choices:
- change(n - choices[0], append_and_compress(coins, choices[0]), choices)
- change(n, coins, choices[1:])
- def main():
- change(7, (), (50, 20, 15, 10, 5, 3, 2, 1))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement