13 ms·
It actually doesn't break, you just have to do the carries as you would during normal addition. You have to read from right to left (1's place, 10's place, 100'
by geoffhotchkiss 13y ago
It actually doesn't break, you just have to do the carries as you would during normal addition. You have to read from right to left (1's place, 10's place, 100's place, and so on). So you're really just converting to base 10.
5th row: 1 5 10 10 5 1
Writing this a bit backwards, 1 * 1 + 5 * 10 + 10 * 100 + 10 * 1000 + 5 * 10000 + 1 * 100000 = 161051 = 11^5.
- tryeng 13y agoYou can of course do this trick in any base. If we choose e.g. base 2^n for the n-th row of pascals triangle, we can use the following code for getting the n-th row of pascals triangle: def pascal(n): base = max(2, 2**n) row = (base+1)**n return [row/base**i % i for i in range(n+1)] Nice, but hopelessly inefficient. :) You can also calculate a binomial coefficient the same way without any looping construct (the exponential operator does the looping for you).