Explanation of the Solution | Minimum Payment for a Credit Card using Binary Search

2. Katas

To see full version of Solution visit GitHub. See below↓

Solution:

  1. Create a function that takes two variables.
  2. We pass to a part of the help variables:
    • start_balance - to duplicate the outstanding balance, later it will come in handy.
    • monthlyPercentRate - monthly percent rate.
    • lowerPay - lower limit of payment.
    • upperPay - upper limit of payment.
    • epsilon - comparison variable.
    • count - for the number of attempts for which the program has found the minimum payment.
  3. We pass to the main part of the program:
    • We will use the cycle while, since we do not know how many attempts we will need.
    • Help variables in the cycle itself:
      • minPay - minimum payment at the moment.
      • OutStandingBalance - original outstanding balance.
      • count - add 1 to the number of attempts.
    • Apply the algorithm, which we disassembled in Example.
    • Check the outstanding balance after one year:
      • If it is larger than epsilon, then we change the lower limit to minPay and we return to item 3.
      • If it is smaller than epsilon, then we change the upper limit to minPay and we return to item 3.
      • In other cases, we exit the cycle
    • Round minPay up to the second digit after the comma and return the string by condition

That's all.

If you liked Katas, you can put star on this repositories, this will motivate me to write similar Katas for you.

Visit Github page: