Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active December 28, 2015 15:39
Show Gist options
  • Save animatedlew/7523404 to your computer and use it in GitHub Desktop.
Save animatedlew/7523404 to your computer and use it in GitHub Desktop.
Finding how many combinations of change can be produced based on a total amount and list of denominations in C#.
namespace CountChange
{
class Program
{
static int CountChange(int money, int[] coins)
{
if (money == 0) return 1;
else if (money < 0 || coins.Length == 0) return 0;
else return CountChange(money - coins.First(), coins) + CountChange(money, coins.Skip(1).ToArray());
}
static void Main(string[] args)
{
int money = 300;
int[] coins = {5, 10, 20, 50, 100, 200, 500};
Console.WriteLine("CountChange: "+CountChange(money, coins));
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment