4 kyu

Counting Change Combinations

57 of 11,264leakymirror

Description:

Write a function that counts how many different ways you can make change for an amount of money, given an array of coin denominations. For example, there are 3 ways to give change for 4 if you have coins with denomination 1 and 2:

1+1+1+1, 1+1+2, 2+2.

The order of coins does not matter:

1+1+2 == 2+1+1

Also, assume that you have an infinite amount of coins.

Your function should take an amount to change and an array of unique denominations for the coins:

  countChange(4, [1,2]) // => 3
  countChange(10, [5,2,3]) // => 4
  countChange(11, [5,7]) //  => 0
  count_change(4, [1,2]) # => 3
  count_change(10, [5,2,3]) # => 4
  count_change(11, [5,7]) # => 0
  count_change(4, {1,2}) // => 3
  count_change(10, {5,2,3}) // => 4
  count_change(11, {5,7}) // => 0
  countChange 4 [1,2] -- => 3
  countChange 10 [5,2,3] -- => 4
  countChange 11 [5,7] -- => 0
  countChange(4, [1,2]) # => 3
  countChange(10, [5,2,3]) # => 4
  countChange(11, [5,7]) # => 0
  (count-change 4 [1,2]) ; => 3
  (count-change 10 [5,2,3]) ; => 4
  (count-change 11 [5,7]) ; => 0
  CountCombinations(4, new[] {1,2}) // => 3
  CountCombinations(10, new[] {5,2,3}) // => 4
  CountCombinations(11, new[] {5,7}) //  => 0
  new ChangeCounter().countChange(4, new int[] {1,2}) // => 3
  new ChangeCounter().countChange(10, new int[] {5,2,3}) // => 4
  new ChangeCounter().countChange(11, new int[] {5,7}) //  => 0
Puzzles
Recursion

More By Author:

Check out these other kata created by leakymirror

Stats:

CreatedSep 18, 2014
PublishedSep 18, 2014
Warriors Trained42812
Total Skips11969
Total Code Submissions55116
Total Times Completed11264
CoffeeScript Completions57
JavaScript Completions3346
Python Completions4740
Haskell Completions562
Clojure Completions174
C# Completions1193
C++ Completions762
COBOL Completions10
C Completions708
D Completions9
Java Completions56
Total Stars1581
% of votes with a positive feedback rating91% of 1130
Total "Very Satisfied" Votes960
Total "Somewhat Satisfied" Votes146
Total "Not Satisfied" Votes24
Ad
Contributors
  • leakymirror Avatar
  • jhoffner Avatar
  • xcthulhu Avatar
  • Unnamed Avatar
  • ahamidou Avatar
  • maevelicious Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • Voile Avatar
  • NunoOliveira Avatar
  • jamad Avatar
  • sazzadshopno Avatar
  • hobovsky Avatar
  • ᛚᚨᚱᛊ ᚺᛖᚾᚱᛁᚲ Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
  • akar-0 Avatar
  • sid114 Avatar
  • KayleighWasTaken Avatar
  • brodiemark Avatar
Ad