title: Number of descendants the person has in a particular generation
body: <p>I am looking a way to calculate number of descendants the person has in a particular generation, but don't know how to do that with scala.</p>
  
  <p>I have a class called "Person" and there are a Vector[Person] to contain children. So family tree is like this:</p>
  
  <pre><code>X:Harald
  |----X:Mike
  |------X:Doe
  |------X:Evelyn
  |------X:Emilia
  |--------X:Mark
  |----------X:Rafael
  |----X:Don
  |------X:Henry
  |------X:Milla
  
  
  class Person(val name: String, val children: Vector[Person]) {
  
      // number of all Descendants
      def count(list:Vector[Person]):Int={
          var s= 0
            for(child &lt;- list)
            {
               s += 1
               s += count(child.children)
            }
          s
      }
  
  
      // Returns the number of descendants the person has in a particular generation.
      def numberOfDescendantsAt(generation: Int): Int = {
  
          var descendants = 0
  
          ...
  
          descendants  
      }
  
  }
  </code></pre>