Skip to content

Commit

Permalink
adding doctests on coin_change.py and fixed some typos (TheAlgorithms…
Browse files Browse the repository at this point in the history
…#1337)

* adding doctests on coin_change.py

* fixed some typos

* Update lib.py
  • Loading branch information
Iqrar99 authored and cclauss committed Dec 18, 2019
1 parent f4779bc commit 1af4c02
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions dynamic_programming/coin_change.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@


def dp_count(S, m, n):
"""
>>> dp_count([1, 2, 3], 3, 4)
4
>>> dp_count([1, 2, 3], 3, 7)
8
>>> dp_count([2, 5, 3, 6], 4, 10)
5
>>> dp_count([10], 1, 99)
0
>>> dp_count([4, 5, 6], 3, 0)
1
"""

# table[i] represents the number of ways to get to amount i
table = [0] * (n + 1)
Expand All @@ -24,7 +36,7 @@ def dp_count(S, m, n):

return table[n]


if __name__ == "__main__":
print(dp_count([1, 2, 3], 3, 4)) # answer 4
print(dp_count([2, 5, 3, 6], 4, 10)) # answer 5
import doctest

doctest.testmod()

0 comments on commit 1af4c02

Please sign in to comment.