• [deleted]
    + 2 comments

    I found easier and cleaner solution. Probably also faster thanks to my "if".

    def main(args: Array[String]) {
     val N = scala.io.StdIn.readInt()
     def factorial(num: Int) = (1 to num).product
     for (n <- 0 to N-1) {
      for (r <- 0 to N) {
       if (r <= n) {
        val x = factorial(n) / (factorial(r) * factorial(n - r))
        print(s"$x ")
       } 
      }
      print("\n")
     }
    }
    

    However still it is far from being perfect due to repeted computation of fatorials... there must be some way how to reuse computations from previous levels. I will try to find it on another day.