coin_change version 0.1

*Given an amount of money and an infinite supply of coins of certain denominations, determine how to give change for that amount so that the least number of coins are used.*

Run

Source (PHP)

```
function coin_change ($amount, $coins)
```

{

$change = array();

rsort($coins);

for($i=0; $i<count($coins); $i++) {

$change[$coins[$i]] = floor($amount/$coins[$i]);

$amount = $amount % $coins[$i];

}

return $change;

}

Tags

coins, money, change

Tools & Information

Rate this algorithm: 23% on 13 votes

Flag: 13 Buggy | 0 Dangerous | 0 Slow | 0 Vandalized

Average run time: 0.000220258 seconds