```On Thu, Nov 20, 2008 at 11:21 AM,  <tirado.carlos / gmail.com> wrote:
> On Nov 19, 3:53 pm, Fernando Villafuerte <fernand... / hemac.com.mx>
> wrote:
>> lo que no se como hacer... es que el
>> pero solo los que son n=FAmeros pares...
>
> Solo te hace falta agregar una variable para la suma, incrementandola
> cuando el numero es par (al dividirlo en 2 el residuo es cero):
>
>> a =3D 1
>> b =3D 2
>> stop =3D 4_000_000
>
> suma =3D 0
>
>> (1...500).each do
>>   s =3D a + b
>>   a =3D b
>>   b =3D s
>
> suma =3D suma + b if 0 =3D=3D b.modulo(2)
>
>>   break if a > stop
>> end
>
> puts =3D suma

For fun (no guarantee of accuracy, but works for 4_000_000)...

include Math
P =3D (1 + R) / 2 #phi
my_number =3D 4_000_000
#inverting my_number to see approximately where n sits for F(n)
max_inverted =3D (log((my_number - 0.5) * R) / log(P)).to_i
#adding up F(n) for 0 to n
even_sum =3D (0..max_inverted).inject do |s, i|
#next line is for direct F(n)
#the inversion above is the opposite of this
fib =3D (((P**i) - (1-P)**i) / R).floor
#see if it's even
fib % 2 =3D=3D 0 ? (s + fib) : s
end
p even_sum

...It would be interesting to see what ceilings (like 4_000_000) this fails=
for.

cheers,
Todd

```