Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.27 KB | None | 0 0
  1. lim = 4000000 # 4 million
  2. fst_term = 1
  3. snd_term = 2
  4. thd_term = 0
  5. sum = 0
  6.  
  7. while ( snd_term < lim )
  8.  
  9.     if ( snd_term % 2 == 0)
  10.         sum = sum + snd_term
  11.     end
  12.  
  13.     thd_term = fst_term + snd_term
  14.     fst_term = snd_term
  15.     snd_term = thd_term
  16. end
  17.  
  18. puts sum
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement