use yield return and ToArray instead of List

In my opinion it is slightly better style to have a lazy enumerable
that reads the input. Let the compiler do the work, instead of
building a list manually. The downside is that reading input is not
pure, so enumerating twice will yield different results. To fix
this, I force evaluation of the enumerable using `ToArray`.
use var instead of complicated generic