For a given balance and an annual interest rate, calculate the minimum fixed monthly payment to pay off debt in a year
This is a problem that can be solved exactly with a little math, so there should be no need to program a search.

Suppose that we borrow initial capital \$c\$ at a monthly interest rate \$r\$, paying it off in \$n\$ months with a monthly payment \$p\$. (Here \$r\$ is expressed as a multiplier, for example if the monthly percentage rate is \$2\%\$ then \$r = 1.02\$.)

In this scenario the outstanding balance is $$ \eqalign{
cr - p &amp;= cr^1 - p(1) &amp; \quad\text{after 1 month;} \\
(cr - p)r - p &amp;= cr^2 - p(1 + r) &amp; \quad\text{after 2 months;} \\
((cr - p)r - p)r - p &amp;= cr^3 - p(1 + r + r^2) &amp; \quad\text{after 3 months;}}$$ and so after \$n\$ months the balance is $$
cr^n - p(1 + r + r^2 + \dots + r^{n - 1}) = cr^n - p{r^n - 1\over r-1}. $$ If this pays off the debt exactly then $$ cr^n - p{r^n - 1\over r-1} = 0 $$ and so $$ p = {cr^n(r-1) \over r^n - 1}.$$

Since payments typically have to be made in integer numbers of pennies (or whatever the minimum unit of account is) then you'll want to round \$p\$ up to the nearest penny.