During my implementation of a visual illustration of Pascal's triangle with Python Mode for Processing for MAC OS X I experienced the following somewhat strange behaviour of Processing compared to e.g. Jupyter.
One of the necessary steps in my project is the calculation of the binomial coefficients in each row of the triangle. I chose to do it in a recursive way instead of calculating factorials. My code works well in Jupyter, but produces different outcomes in Processing.
rows = 301
pascal=[[1], [1,1]]
for i in range (rows):
last_row = pascal[len(pascal)-1]
next_row = [1] +[last_row[i]+last_row[i+1] for i in range(len(last_row)) if i < len(last_row)-1] +[1]
pascal.append(next_row)
print (pascal[35][16])
The problems begin in row 35 of the triangle (countig starts from 0). The 16th element in this row should be 4059928950 but Processing calculates -235038346. And from then on, the calculations in Processing seem to be often wrong. I guess it is an integer overflow problem, but I am not sure.
During my implementation of a visual illustration of Pascal's triangle with Python Mode for Processing for MAC OS X I experienced the following somewhat strange behaviour of Processing compared to e.g. Jupyter.
One of the necessary steps in my project is the calculation of the binomial coefficients in each row of the triangle. I chose to do it in a recursive way instead of calculating factorials. My code works well in Jupyter, but produces different outcomes in Processing.
The problems begin in row 35 of the triangle (countig starts from 0). The 16th element in this row should be 4059928950 but Processing calculates -235038346. And from then on, the calculations in Processing seem to be often wrong. I guess it is an integer overflow problem, but I am not sure.