A loan can be described very simply by a differential equation. Specifically,

\[\dot x = rx - p\]

where $x(t)$ is the amount you owe $t$ years after taking out the loan, $r$ is the yearly interest rate $p$ is the amount you repay per year. In the example you provided we would have $r = 0.06$ and $p = 1,000$ and an initial loan of $x(0) = 10,000$. Now, the solution to this equation is particularly simple since it's linear. The computation basically boils down to

\[\frac{d}{dt} (x - \frac{p}{r}) = r(x - \frac{p}{r}) \implies x - \frac{p}{r} = (x(0) - \frac{p}{r})e^{rt} \implies x(t) = (x(0) - \frac{p}{r})e^{rt} + \frac{p}{r} \]

This equation can now be applied for any choice of $r, p, x(0)$.

Now, you want to know how long until it is repaid which is the same as asking for the value of $t$ for which $x(t) = 0$. This is again an easy equation to solve. For your example you get $t = \frac{\log \frac{5}{2}}{.06} \approx 15.272$ years.