Last active
December 28, 2015 15:39
-
-
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#.
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
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