title: more ruby way of doing project euler #2
body: <p>I'm trying to learn Ruby, and am going through some of the Project Euler problems. I solved <a href="http://projecteuler.net/index.php?section=problems&amp;id=2" rel="nofollow noreferrer">problem number two</a> as such:</p>
  
  <pre><code>def fib(n)
    return n if n &lt; 2
    vals = [0, 1]
    n.times do
      vals.push(vals[-1]+vals[-2])
    end
    return vals.last
  end
  i = 1
  s = 0
  while((v = fib(i)) &lt; 4_000_000)
    s+=v if v%2==0
    i+=1
  end
  puts s
  </code></pre>
  
  <p>While that works, it seems not very ruby-ish—I couldn't come up with any good purely Ruby answer like I could with the first one ( <code>puts (0..999).inject{ |sum, n| n%3==0||n%5==0 ? sum : sum+n }</code>). </p>