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 →

  • strawstack 4 years ago+ 0 comments

    UPDATE: The program now prints a nested array. Still trying to get Haskell to format basic output? (Output of below is [[1],[1,1],[1,2,1],[1,3,3,1]])

    -- print tri value at coords
    pas m n
        | n == 0 = 1 
        | m == n = 1
        | otherwise = pas (m-1) (n-1) + pas (m-1) n
          
    -- print row of triangle 
    row m = map (pas m) [0..m]   
        
    -- print triangle until row
    tri m = map (row) [0..(m-1)] 
        
    main = do   
       m <- readLn :: IO Int
       print (tri m) -- print tri to row m
    
    1|
    ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature