// P35 (**) Determine the prime factors of a given positive integer.
// Construct a flat list containing the prime factors in ascending order.
//
// scala> 315.primeFactors
// res0: List[Int] = List(3, 3, 5, 7)
class S99Int(val start: Int) {
def primeFactors: List[Int] = {
def primeFactorsR(n: Int, ps: Stream[Int]): List[Int] =
if (n.isPrime) List(n)
else if (n % ps.head == 0) ps.head :: primeFactorsR(n / ps.head, ps)
else primeFactorsR(n, ps.tail)
primeFactorsR(start, primes)
}
}