Yes, I would consider that an improvement, though I might go back to a generator with:

from math import sqrt

rt5 = sqrt(5)
phi = (1 + rt5)/2

def neat_formula(f0, f1, f2):
    while True:
        yield (f0 + f2 + rt5*f1)/2
        f0, f1, f2 = f1, f2, f1+f2

power_of_phi = phi**(-6)
results = neat_formula(13, -8, 5)  # seed me
for k in range(20):
    print("{0:8.5f} {1:8.5f}".format(power_of_phi, next(results)))
    power_of_phi *= phi

Going back and forth between yours and mine is introducing a small delta, so if the game were to introduce generators as a genre, I could see doing a bunch of small deltas like this.

Kirby



On Sat, Nov 23, 2013 at 10:54 AM, Litvin <litvin@skylit.com> wrote:
Kirby,

You are right, a little program does help to clarify the statement and the formulas involved.  But then, keep it really simple (no classes, no generators), so that understanding of the code doesn't get in the way.  For example:

from math import sqrt

rt5 = sqrt(5)
phi = (1 + rt5)/2

def neat_formula(f0, f1, f2):
    return (f0 + f2 + rt5*f1)/2

power_of_phi = phi**(-6)
f0, f1, f2 = 13, -8, 5
for k in range(20):
    print("{0:8.5f} {1:8.5f}".format(power_of_phi, neat_formula(f0, f1, f2)))
    f0, f1, f2 = f1, f2, f1+f2
    power_of_phi *= phi

There are many other occasions to bring in more advanced tools.

Gary Litvin
www.skylit.com