Skip to content

Instantly share code, notes, and snippets.

@adamwitko
Last active August 29, 2015 13:56

Revisions

  1. adamwitko revised this gist Feb 7, 2014. 1 changed file with 19 additions and 19 deletions.
    38 changes: 19 additions & 19 deletions COINS=WIN
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,24 @@
    internal class Program
    {
    private static readonly int[] _denominations = {1, 2, 5};
    internal class Program
    {
    private static readonly int[] _denominations = {1, 2, 5};

    private static void Main(string[] args)
    {
    const int total = 6;
    private static void Main(string[] args)
    {
    const int total = 6;

    var result = GetCount(amount, 0);
    var result = GetCount(amount, 0);

    Console.WriteLine(result);
    Console.ReadLine();
    }
    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;
    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);
    }
    }
    return GetCount(amount - _denominations[index], index) + GetCount(amount, index + 1);
    }
    }
  2. adamwitko renamed this gist Feb 7, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. adamwitko revised this gist Feb 7, 2014. 1 changed file with 3 additions and 8 deletions.
    11 changes: 3 additions & 8 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -6,24 +6,19 @@
    {
    const int total = 6;

    var result = GetCount(total);
    var result = GetCount(amount, 0);

    Console.WriteLine(result);
    Console.ReadLine();
    }

    public static int GetCount(int amount)
    {
    return Recurse(amount, 0);
    }

    public static int Recurse(int amount, int index)
    public static int GetCount(int amount, int index)
    {
    if (amount == 0)
    return 1;
    if (amount < 0 || _denominations.Length == index)
    return 0;

    return Recurse(amount - _denominations[index], index) + Recurse(amount, index + 1);
    return GetCount(amount - _denominations[index], index) + GetCount(amount, index + 1);
    }
    }
  4. adamwitko revised this gist Feb 7, 2014. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -17,13 +17,13 @@
    return Recurse(amount, 0);
    }

    public static int Recurse(int amount, int checkFromIndex)
    public static int Recurse(int amount, int index)
    {
    if (amount == 0)
    return 1;
    if (amount < 0 || _denominations.Length == checkFromIndex)
    if (amount < 0 || _denominations.Length == index)
    return 0;

    return Recurse(amount - _denominations[checkFromIndex], checkFromIndex) + Recurse(amount, checkFromIndex + 1);
    return Recurse(amount - _denominations[index], index) + Recurse(amount, index + 1);
    }
    }
  5. adamwitko created this gist Feb 6, 2014.
    29 changes: 29 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    internal class Program
    {
    private static readonly int[] _denominations = {1, 2, 5};

    private static void Main(string[] args)
    {
    const int total = 6;

    var result = GetCount(total);

    Console.WriteLine(result);
    Console.ReadLine();
    }

    public static int GetCount(int amount)
    {
    return Recurse(amount, 0);
    }

    public static int Recurse(int amount, int checkFromIndex)
    {
    if (amount == 0)
    return 1;
    if (amount < 0 || _denominations.Length == checkFromIndex)
    return 0;

    return Recurse(amount - _denominations[checkFromIndex], checkFromIndex) + Recurse(amount, checkFromIndex + 1);
    }
    }