We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Practice
  • Certification
  • Compete
  • Career Fair
  • Hiring developers?
  1. Practice
  2. Functional Programming
  3. Recursion
  4. Pascal's Triangle
  5. Discussions

Pascal's Triangle

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • neild799 3 years ago+ 0 comments
    object Solution {
        def nthRow(n: Int): List[Int] = {
            val row = List(1);
            (0 until n).foldLeft[List[Int]](row)((acc, r) => acc.head*(n-r)/(r+1)::acc);
        }
    
        def main(args: Array[String]) {
            (0 until scala.io.StdIn.readInt()).foreach(
                    i => {
                        nthRow(i).foreach(x => print(x + " "));
                        println();
                    }
                );
            }
    }
    
    0|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature