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.
Loading...
  • Practice
  • Compete
  • Jobs
  • Leaderboard
  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 →

  • AlexNetkachov 1 year ago+ 1 comment

    Quite consise F# solution for generating lines:

    let lines n =
      let rec build (prev : int list) i =
        [ if i < n then
            let line = [ yield 1
                         for p in Seq.pairwise prev do
                           yield (fst p) + (snd p)
                         yield 1 ]
            yield line
            yield! build line (i+1) ]
      [ yield [1]; yield! build [1] 1 ]
    

    A few more solutions: https://alexatnet.com/hr-f-pascals-triangle/

    1|
    Permalink
    • denis631 1 year ago+ 0 comments

      Nice. I didn't know I can do pairwise foreach :)

      0|
      ParentPermalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature