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):...

c,largenumber,pascals-triangle

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...

java,arrays,static-methods,pascals-triangle

In line 28 you create one-dimensional array which still holds null values assigned by default. In line 30 you replace each null by new array, which size is one more than its index. 2D-array in Java is not actually a matrix. It is array of arrays, so it doesn't...

First, your code will be very slow. I'm not going to do your assignment, but you can compute the next line of Pascal's triangle by just knowing the previous one, in constant time for each cell, while you are currently using a huge time re-computing the same values. Second, for...

algorithm,math,pascals-triangle

EDIT This solution needs Logarithmic time, it's O(Log z). Or maybe O( (Log z)^2 ). Say you are looking for n,k where Binomial(n,k)==z for a given z. Each row has its largest value in the middle, so starting from n=0 you increase the row number, n, as long as the...

arrays,algorithm,pascals-triangle,binomial-coefficients

Here is a code which uses only one one dimensional array: int[] coefficients = new int[k + 1]; coefficients[0] = 1; for (int i = 1; i <= n; i++) { for (int j = k; j >= 1; j--) { coefficients[j] += coefficients[j - 1]; } } Why is...

This works because Pascal's triangle can be represented with binomial coefficients : This formula in your code is based on the fact that, on the same n-index (in the pascal's triangle case, same line), in order to get the next element (k -> k+1), we need to multiply the current...

(int) truncate double number before conversion. Try this code instead public static List<int> GetRow(int rowIndex) { List<int> l = new List<int>(); l.Add(1); for (int i = 1; i <= rowIndex; i++) { int nextNum = (int)Math.Round(((rowIndex + 1 - i) / (double)i) * l[i - 1]); l.Add(nextNum); } return l;...

python,algorithm,pascals-triangle

Math.pow works with floats, so solution may be inexact for large exponent. Moreover, for values over 1023, it throws OverflowError. Use x ** y operator instead, or builtin pow function....