Your task is to check if a given sum can be made using a given set of coins. For example, the sum can be made using the coins (e.g., ), but not using the coins .
In a file coinsum.py
, implement the function can_create
that takes a list of coins and the target sum as parameters. The function should return True
if the sum can be achieved, and False
otherwise.
Implement the function efficiently using dynamic programming similarly to the examples in the course material.
def can_create(coins, target): # TODO if __name__ == "__main__": print(can_create([1, 2, 5], 13)) # True print(can_create([2, 4, 6], 13)) # False print(can_create([1], 42)) # True print(can_create([2, 4, 6], 42)) # True print(can_create([3], 1337)) # False print(can_create([3, 4], 1337)) # True