function coin_change(coins, amount): # fewest coins to make amount
   best = [infinity] * (amount + 1)

   best[0] = 0
   for total from 1 to amount:
      for coin in coins:
        if coin <= total:
           best[total] = min(best[total], 1 + best[total - coin])

   return best[amount]       # builds the answer from smaller subpr
 oblems
