Last active
August 29, 2015 13:56
-
-
Save adamwitko/8853375 to your computer and use it in GitHub Desktop.
My attempt at a recursive coin change combo challenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Program | |
{ | |
private static readonly int[] _denominations = {1, 2, 5}; | |
private static void Main(string[] args) | |
{ | |
const int total = 6; | |
var result = GetCount(amount, 0); | |
Console.WriteLine(result); | |
Console.ReadLine(); | |
} | |
public static int GetCount(int amount, int index) | |
{ | |
if (amount == 0) | |
return 1; | |
if (amount < 0 || _denominations.Length == index) | |
return 0; | |
return GetCount(amount - _denominations[index], index) + GetCount(amount, index + 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment