Pascal’s Triangle for Python

OK code review: import math # pascals_tri_formula = [] # don’t collect in a global variable. def combination(n, r): # correct calculation of combinations, n choose k return int((math.factorial(n)) / ((math.factorial(r)) * math.factorial(n – r))) def for_test(x, y): # don’t see where this is being used… for y in range(x): return combination(x, y) def pascals_triangle(rows): … Read more

Pascal’s Triangle in C

Factorials get really big really fast (scroll down a little to see the list). Even a 64-bit number is only good up to 20!. So you have to do a little preprocessing before you start multiplying. The general idea is to factor the numerator and the denominator, and remove all of the common factors. Since … Read more