Code Monkey home page Code Monkey logo

optimalchangekata's Introduction

.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

optimalchangekata's People

Contributors

aimenux avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.