Error in Pascal's Triangle

In the Pascal’s triangle exercise, the instructions tell us that each number is computed by adding the numbers to the right and left of the current position in the previous row.

This is incorrect, to my understanding. You compute a number by adding a the number and the number on its left in the current position in the previous row. Am I right?

According to the instructions, to compute 6 you add the numbers to the left and right of 6 in the previous row. So that would be 3 + 3. Looks fine to me. Maybe i’m missing something?

It all depends on how you align each row. The way the triangle is displayed, for a given number X, there is no number directly above X or “in the same position as X” in the prior line.

How each line is stored internally may differ from how it is displayed visually.

1 Like

To illustrate @IsaacG’s point:

1                  1
1 1               1 1
1 2 1     vs.    1 2 1
1 3 3 1         1 3 3 1
1 4 6 4 1      1 4 6 4 1
1 Like

So the primary issue here seems to be the wording. If “current position” is to be taken graphically, then this makes sense: as @IsaacG says, the way the triangle is displayed, there is no number in the current position in the previous row, and thus we must see the left and right numbers.

However, programmatically, “current position” invokes “index”. That is, to reply to @tasx, 6 has index 2 in row 4 (0-based indexing), so index 1 + index 3 in row 3 = 3 + 1 = 4, which is incorrect.

Considering that this is a programming platform, I think the second interpretation is more valid. Furthermore, mathematically, we’re taught to add the number in the current position in the previous row and the number to the left of it (mathematically, we tend to use @MatthijsBlom’s first diagram). I therefore propose that we a) make it clearer by saying “current index” instead of “current position”, and b) change it the computation method to the number in the current index plus the one to the left of it.

The instructions have a visual representation and discuss the representation. An important part of learning to program involves mapping requirements (not written in programming lingo) to code (impression). I think the “more correct” interpretation of the prose is that the prose is talking about the representation laid out in the prose, and that the requirements are discussing requirements, not making references to potential implementations.

Note this exercise can be implemented without using any indexing at all. Talking about the index value found in the implementation would be making assumptions (requirements?) about the implementation which may very well be wrong.

1 Like

I agree. That means that we shouldn’t use the word index.

I then suggest that we, in the prose, use the more mathematically conventional diagram and prose: that is, MatthijsBlom’s first diagram and “the number above plus the one to the left of it”. This will reduce confusion.

I’m entirely unfamiliar with this mathematical convention. In the diagram, the numbers in the prior row are either to the left or to the right of the new number. Is this mathematics specific lingo? I (and many of the students here) have never studied higher math. The prose aims to avoid technical jargon.

I never thought of “current position” as an index. Pascal’s triangle is a mathematical construct so why introduce an index when you don’t need one? Also, I don’t see why the wording should be precise when there’s a diagram that perfectly illustrates how the triangle is constructed.

In any case, for me the biggest issue here is that the link to mathworld initially shows a different triangle. So i would prefer to change the link to something else (wikipedia has a nice animation that shows which numbers are added) or change the triangle (and the instructions) to match the triangle from mathworld. Btw, the most common representation of the triangle is the one already depicted in the instructions, that’s how most people are introduced to this concept.

6 posts were split to a new topic: Higher Math Thread - Pascal’s Triangle

While I’m undecided in the debate that follows, I agree about this. There’s no “technical jargon”.

Anyway, if most people find this understandable, then that’s fine. However, the wording “the right and left of the current position” is ambiguous, in my opinion, as there is no number directly above (in the current position) in the previous row (in the given diagram), only a blank space. I think “two numbers diagonally above” is much better, what about the others?

I don’t believe the instructions imply that there should be a number in that position, but i now see your initial point . Assuming the “position” refers to the position of a number in a row, the same position in the previous row refers to the number that is diagonally above and to the right of the current position. Changing to “two numbers diagonally above” would be more appropriate indeed.

I would also like to see the link replaced with a link to the wikipedia article. The mathworld link mentions “adding the two entries diagonally above” but it refers to the right triangle that was just introduced. According to the article 10 should be calculated from 4 + 4. Just wrong.

1 Like

Agreed, tasx! Shall I implement this change, @IsaacG?

I think the general consensus of the maintainers here is that there is no need to change. In the diagram, elements in the prior row are either to the left or to the right.

Do you see any specific changes in this topic that people generally agreed would be good? I’m not sure what changes you’re thinking of implementing. I can’t suggest going forward with implementing “this change” when there’s no specific change that people agreed is worth doing.

Are either of you Exercism maintainers? Consensus has to come from Exercism maintainers here.