Skip to content

Instantly share code, notes, and snippets.

@mofas
Last active September 2, 2019 21:49
Show Gist options
  • Save mofas/49155b6f01a312c3944da3d807fab778 to your computer and use it in GitHub Desktop.
Save mofas/49155b6f01a312c3944da3d807fab778 to your computer and use it in GitHub Desktop.
Coin changes
dfs (remainCoins, target):
if target === 0:
# calculate what coins you used here
usedCoin = ...
results.append(usedCoin)
return
if target < 0:
return
for coin in remainCoins:
if remainCoins[coin] > 0:
remainCoins[coin]-= 1
dfs(remainCoins, target - coin)
remainCoins[coin]+= 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment