title: Suggest a cleaner functional way
body: <p>Here is some imperative code:</p>
  
  <pre><code>var sum = 0
  val spacing = 6
  var x = spacing
  for(i &lt;- 1 to 10) {
    sum += x * x
    x += spacing
  }
  </code></pre>
  
  <p>Here are two of my attempts to "functionalize" the above code:</p>
  
  <pre><code>// Attempt 1
  (1 to 10).foldLeft((0, 6)) {
    case((sum, x), _) =&gt; (sum + x * x, x + spacing)
  }
  
  // Attempt 2
  Stream.iterate ((0, 6)) { case (sum, x) =&gt; (sum + x * x, x + spacing) }.take(11).last
  </code></pre>
  
  <p>I think there might be a cleaner and better functional way to do this. What would be that?</p>
  
  <p>PS: Please note that the above is just an example code intended to illustrate the problem; it is not from the real application code.</p>