Skip to content

Instantly share code, notes, and snippets.

@adamwitko
Last active August 29, 2015 13:56
Show Gist options
  • Save adamwitko/8853375 to your computer and use it in GitHub Desktop.
Save adamwitko/8853375 to your computer and use it in GitHub Desktop.
My attempt at a recursive coin change combo challenge
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