Hacker News new | past | comments | ask | show | jobs | submit login

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



Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: