Monthly Archives: February 2015

Python: Problem Set 1

This week’s problem set involved calculating credit card payments and interest rates over time. The objective comes with three sub-tasks: calculating payments over a fixed period, finding the amount required to pay debt in 12 months through exhaustive enumeration, and improving this second task using binary search.

concepts covered in lecture:

  • Exhaustive enumeration often the right solution
  • Break exits only the current loop
  • If the answer falls outside the range tested, answer won’t be found
  • E.g. range(0, 100) when answer is negative

Paying the Minimum

Paying off debt in 12 months

(brute force method)

(binary search method)

If you made it this far, thank you for reading. I am aware I should be using decimal types, no floats, for much of the calculation here. I spent too much time trying to get decimal to work and failing, so I used float formatting and moved on.

Critiques and questions are appreciated.