Calculate APR (annual percentage rate) Programmatically

I suppose you want to compute X from your equation. This equation can be written as

f(y) = y + y**2 + y**3 + ... + y**N - L/P = 0

where

X = APR
L = Loan (6000)
P = Individual Payment (274.11)
N = Number of payments (24)
F = Frequency (12 per year)
y = 1 / ((1 + X)**(1/F))   (substitution to simplify the equation)

Now, you need to solve the equation f(y) = 0 to get y. This can be done e.g. using the Newton's iteration (pseudo-code):

y = 1  (some plausible initial value)
repeat 
    dy = - f(y) / f'(y)
    y += dy
until abs(dy) < eps 

The derivative is:

f'(y) = 1 + 2*y + 3*y**2 + ... + N*y**(N-1)

You would compute f(y) and f'(y) using the Horner rule for polynomials to avoid the exponentiation. The derivative can be likely approximated by some few first terms. After you find y, you get x:

x = y**(-F) - 1