Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $coins = [1, 2];
- $totalAmount = 4;
- function calculateCombo(array $coins, int $amount, int $currentindex)
- {
- if($amount == 0) { return 1; }
- if($amount < 0) { return 0; }
- $combos = 0;
- for($i = $currentindex; $i < count($coins); $i++)
- {
- $combos = $combos + calculateCombo($coins, $amount - $coins[$i], $i);
- }
- return $combos;
- }
- echo calculateCombo($coins, $totalAmount, 0);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement