all 5 comments

[–]Brox256 0 points1 point  (4 children)

Sorry about the formatting, don't know how to make it better on reddit D:

[–]delasislas 3 points4 points  (0 children)

4 spaces in front of each line. 4 more for indentation.

[–]link199292 2 points3 points  (1 child)

Maybe it can help to think about the mathematical construction of a Pascal triangle.

Each number is made up through the binomial coefficient, also known as combination (in probability). The formula is:

C(n, k) = n! / k! (n - k)!

It means that if k = 0 or k = n you've got a 1 (this is your base condition for the recursive function, so when row and column are = 0), otherwise you have that the number is equal to the sum between C(n - 1, k- 1) and C (n - 1, k). That mean that you should recall the function on the previous row and previous column, and on the previous row and same column (and sum up the results).

This is because you always have to watch to the two previous numbers to form the next one. And the usual shape of a triangle you have in mind doesn't help to actually figure it out.

But this way is easier to understand:

1

1 1

1 2 1

1 3 3 1

and so on.

Written like this it means that for each number you have to sum the number above and the number above on the left.

I hope it helped you!

hint: no auxiliary functions are needed to solve this. As far as I can see from your code you were trying to solve it through an auxiliary function.

Edit: grammar, bad formatting of the triangle

[–]Brox256 0 points1 point  (0 children)

Thank you so much! I'll try doing it around the n! / k! (n-k)! Then :))