This notebook was prepared by Donne Martin. Source and license info is on GitHub.

Challenge Notebook

Problem: Determine the total number of unique ways to make n cents, given coins of denominations less than n cents.


  • Do the coins have to reach exactly n cents?
    • Yes
  • Can we assume we have an infinite number of coins to make n cents?
    • Yes
  • Do we need to report the combination(s) of coins that represent the minimum?
    • No
  • Can we assume the coin denominations are given in sorted order?
    • No
  • Can we assume this fits memory?
    • Yes

Test Cases

  • coins: None or n: None -> Exception
  • coins: [] or n: 0 -> 0
  • coins: [1, 2, 3], n: 5 -> 5


Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.


In [ ]:
class CoinChanger(object):

    def make_change(self, coins, total):
        # TODO: Implement me
        return n

Unit Test

The following unit test is expected to fail until you solve the challenge.

In [ ]:
# %load
import unittest

class Challenge(unittest.TestCase):

    def test_coin_change(self):
        coin_changer = CoinChanger()
        self.assertEqual(coin_changer.make_change([1, 2], 0), 0)
        self.assertEqual(coin_changer.make_change([1, 2, 3], 5), 5)
        self.assertEqual(coin_changer.make_change([1, 5, 25, 50], 10), 3)
        print('Success: test_coin_change')

def main():
    test = Challenge()

if __name__ == '__main__':

Solution Notebook

Review the Solution Notebook for a discussion on algorithms and code solutions.