From: Todd Benson Date: 2008-12-09T08:38:36+09:00 Subject: Re: Ayuda con Ejercicio > For fun (no guarantee of accuracy, but works for 4_000_000)... > > include Math > R = Math.sqrt(5) #radical > P = (1 + R) / 2 #phi > my_number = 4_000_000 > #inverting my_number to see approximately where n sits for F(n) > max_inverted = (log((my_number - 0.5) * R) / log(P)).to_i > #adding up F(n) for 0 to n > even_sum = (0..max_inverted).inject do |s, i| When you do (max_inverted + 1) in the previous line, this works for 4_000_000. > #next line is for direct F(n) > #the inversion above is the opposite of this > fib = (((P**i) - (1-P)**i) / R).floor > #see if it's even > fib % 2 == 0 ? (s + fib) : s > end > p even_sum > > > ...It would be interesting to see what ceilings (like 4_000_000) this fails for. Revisiting old emails. Sorry for noise, but important to be concise. Todd