Skip to content

Instantly share code, notes, and snippets.

@dobeerman
Created August 10, 2021 05:15
Show Gist options
  • Select an option

  • Save dobeerman/3b4692fbe60abd89db39e8ba5f0c513b to your computer and use it in GitHub Desktop.

Select an option

Save dobeerman/3b4692fbe60abd89db39e8ba5f0c513b to your computer and use it in GitHub Desktop.

Revisions

  1. dobeerman created this gist Aug 10, 2021.
    29 changes: 29 additions & 0 deletions dispenseBanknotes.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    /**
    * Say, a customer requires $247 from an ATM machine.
    * What is the combination of bank notes ($100, $50, $20, $10, $5, $1)
    * that satisfies that request?
    */
    class RequestBill {
    private pairs: number[][];

    constructor(private amount: number) {
    this.pairs = [];
    }

    get(bill: number) {
    var count = Math.floor(this.amount / bill);
    this.amount -= count * bill;
    this.pairs.push([count, bill])
    return this;
    }

    getPairs() {
    return this.pairs
    }
    }

    const request = new RequestBill(378);

    request.get(100).get(50).get(20).get(10).get(5).get(1);

    console.log(request.getPairs())