Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8819499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:22:33+00:00 2026-06-14T05:22:33+00:00

I am facing a problem on creating pascal triangle. The code is given below.

  • 0

I am facing a problem on creating pascal triangle. The code is given below. Here sumLstElts will sum the elements on a row, putBetween will put the sum at the right side of the [1]. pascal n will give us the series of pascal sequences in a row.

    sumLstElts (x:[])=[x]
    sumLstElts []=[]
    sumLstElts xs=[head xs+head(tail xs)]++sumLstElts (tail xs)

    putBetween xs'= [1]++xs''
            where xs''=sumLstElts xs'

    pascal 0=[1]
    pascal n= putBetween(pascal (n-1)) ++ pascal(n-1)

Would u pls help me to identify my error?
thnx in advance.

saugata

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:22:34+00:00Added an answer on June 14, 2026 at 5:22 am

    If you want just the n-th row,

    pascal n= putBetween(pascal (n-1))
    

    is the right way, putBetween already constructs the complete next row from a given. If you want to create the triangle as a list of rows, something like

    pascal :: Int -> [[Integer]]
    pascal n = take (n+1) $ iterate putBetween [1]
    

    would construct the triangle starting with row 0. If you want the part of the triangle in reverse order, longer rows first,

    pascal :: Int -> [[Integer]]
    pascal 0 = [[1]]
    pascal n = putBetween top : previous
      where
        previous = pascal (n-1)
        top = head previous
    

    does that.

    The problem with your attempt is that putBetween is applied to the entire result of pascal (n-1), which is intended to contain not only the n-1-st row, but also the previous rows. So pascal 1 gave the concatenation of the first row [1,1] with the zeroth [1], and when pascal 2 applies putBetween to that, it’s not a row of Pascal’s triangle, so the result isn’t one either. You could also get the concatenation of the rows by

    pascal 0 = [1]
    pascal n = putBetween (take n previous) ++ previous
      where
        previous = pascal (n-1)
    

    but in my opinion it’s better to have the triangle as a list of rows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a problem while creating a static cursor in DB2. This is
Am facing a problem, while creating components through TOM API using .NET/COM Interop. Actual
I am creating a website and am facing the following problem. I have 2
I'm creating a User Interface using PyQt4 module . the problem i'am facing is
Iam facing problem in understanding and converting a matlab code into opencv. I want
iam facing problem in passing array to view. this is my controller code.. function
I am facing problem while setting focus in EdiText. Below is my EditText property.
Again expecting your helps. Facing a small might be stupid problem. I am creating
I am facing a problem creating a Json which is actually a complex one
I am facing problem while creating sign-up portlet in Liferay 6.1 and store user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.