title: Fibonacci One-Liner
body: <p>I'm trying to solve questions from <a href="http://www.projecteuler.net" rel="noreferrer">Project Euler</a> in Ruby one-liners, and I'm curious if there's a more elegant solution for <a href="http://projecteuler.net/index.php?section=problems&amp;id=2" rel="noreferrer">question two</a>:</p>
  <blockquote>
  <p>Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:</p>
  <p>1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...</p>
  <p>By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.</p>
  </blockquote>
  <p>Here is my one line solution in Ruby:</p>
  <pre><code>(1..32).inject([0,1]) {|arr, i| (arr &lt;&lt; arr[-1] + arr[-2] if arr[-1] + arr[-2] &lt;= 4000000) || arr}.inject(0) {|total, i| total += i.even? ? i : 0}
  </code></pre>
  <p>My main concern here is that I'm using the range (1..32) only because I happen to know that that's all that's necessary until numbers in the Fibonacci sequence begin to exceed 4,000,000. I would prefer that this be built into the one-line somehow, but I haven't been able to figure it out.</p>
  <p><em>Semi-colons are not allowed!</em></p>