title: Sums of different lists using recursion
body: <p>I am doing CodeWars challenges again and today I have a problem with this one:</p>
  
  <p>Let us consider this example (array written in general format):</p>
  
  <pre><code>ls = [0, 1, 3, 6, 10]
  </code></pre>
  
  <p>Its following parts:</p>
  
  <pre><code>ls = [0, 1, 3, 6, 10]
  ls = [1, 3, 6, 10]
  ls = [3, 6, 10]
  ls = [6, 10]
  ls = [10]
  ls = []
  </code></pre>
  
  <p>The corresponding sums are (put together in a list): [20, 20, 19, 16, 10, 0]</p>
  
  <p>The function parts_sums (or its variants in other languages) will take as parameter a list ls and return a list of the sums of its parts as defined above.</p>
  
  <pre><code>object SumsOfParts {
  
    def partsSums(l: List[Int]): List[Int] = {
  
      var x: List[Int] = List()
      if (l.isEmpty)
        x
      else {
        x :+ l.sum
        partsSums(l.tail)
      }
    }
  }
  
  </code></pre>
  
  <p>Here are the test samples: </p>
  
  <blockquote>
    <p>partsSums(List(0, 1, 3, 6, 10)) should return List(20, 20, 19, 16, 10, 0)
    Test Failed</p>
    
    <p>tail of empty list
    Stack Trace
    Completed in 4ms
    partsSums(List(1, 2, 3, 4, 5, 6)) should return List(21, 20, 18, 15, 11, 6, 0)
    Test Failed</p>
    
    <p>tail of empty list
    Stack Trace
    partsSums(List(744125, 935, 407, 454, 430, 90, 144, 6710213, 889, 810, 2579358)) should return List(10037855, 9293730, 9292795, 9292388, 9291934, 9291504, 9291414, 9291270, 2581057, 2580168, 2579358, 0)
    Test Failed</p>
    
    <p>tail of empty list
    Stack Trace
    Completed in 1ms
    partsSums(List(30350, 76431, 156228, 78043, 98977, 80169, 32457, 182875, 162323, 17508, 57971, 171907)) should return List(1145239, 1114889, 1038458, 882230, 804187, 705210, 625041, 592584, 409709, 247386, 229878, 171907, 0)
    Test Failed</p>
  </blockquote>