Skip to content

Instantly share code, notes, and snippets.

@profesor79
Last active April 30, 2018 10:54
Show Gist options
  • Save profesor79/138dfd75ada6e4bbad2bffd66d6fb8b2 to your computer and use it in GitHub Desktop.
Save profesor79/138dfd75ada6e4bbad2bffd66d6fb8b2 to your computer and use it in GitHub Desktop.
a dirty atm cash dispenser solution
void Main()
{
var atm = new AtmDispenser();
var value = 250;
var notes = atm.GetTheCash (value).Dump($" value: {value}");
value = 230;
notes = atm.GetTheCash (value).Dump($" value: {value}");
value = 370;
notes = atm.GetTheCash (value).Dump ($" value: {value}");
value = 260;
notes = atm.GetTheCash (value).Dump ($" value: {value}");
value = 40;
notes = atm.GetTheCash (value).Dump ($" value: {value}");
value = 50;
notes = atm.GetTheCash (value).Dump ($" value: {value}");
value = 60;
notes = atm.GetTheCash (value).Dump ($" value: {value}");
}
// Define other methods and classes here
public class AtmDispenser {
public List<int> GetTheCash (int amout) {
// we can have a 210, whic in easy way
if (amout < 40 | amout > 1000) {
throw new IndexOutOfRangeException("Value is not in range");
}
int numberOf100 = amout / 100;
var restAfter100 = amout % 100;
var restAfter100Flag = (restAfter100 / 10);
// if we will have 10 and 30 we need to decrease amout of 100
if (restAfter100Flag==1 || restAfter100Flag==3)
{
numberOf100--;
}
var remainig50=amout - numberOf100*100;
int numberOf50 = (remainig50/50);
var restAfter50 = remainig50 % 50;
if ((restAfter50 % 20) != 0) {
numberOf50--;
}
var remainig20 = remainig50-numberOf50*50;
int numberOf20 = remainig20/20;
return new List<int> {numberOf100, numberOf50, numberOf20};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment