Skip to content

Latest commit

 

History

History
50 lines (48 loc) · 2.18 KB

README.md

File metadata and controls

50 lines (48 loc) · 2.18 KB

.NET Coverage

OptimalChangeKata

Kata about the optimal way to give back amount with the minimum number of coins

One of the problems presented by cash transactions is how to return change. What is the optimal way to give back a certain amount with the minimum number of coins. It's an issue that each of us encounters on a daily basis and the problem is the same for automated checkout machines. In this exercise, you are asked to try and find an optimal solution for returning change in a very specific case :

⚡ When the machine contains only €2 coins, €5 coins and €10 coins.

⚡ We imagine that all coins are available in unlimited quantities.

Here are some examples of how change may be returned :

📌 Change For €1:

  Possible Solutions: Impossible
  Optimal Solution:   Impossible

📌 Change For €6:

  Possible Solutions: €2 + €2 + €2
  Optimal Solution:   €2 + €2 + €2

📌 Change For €10:

  Possible Solutions: €2 + €2 + €2 + €2 + €2 | €5 + €5 | €10
  Optimal Solution:   €10

📌 Change For €9223372036854775807:

  Possible Solutions: ...
  Optimal Solution:   (€10 * 922337203685477580)+ €5 + €2

Implement the ComputeOptimalCurrency(long money) method which returns a Currency object. This object has properties TwoCoins, FiveCoins and TenCoins which represents coins for €2, €5 and €10. The sum of coins indicated in the Currency object must be equal to money. If it is not possible to give back change, the method must return null. The solution (when possible) should have the minimal number of coins.

Constraints

money is a long.

⚡ 0 < money <= 9223372036854775807

Tools : vs22, net 7.0, nunit, fluentassertions, guardclauses