Skip to main content
deleted 6 characters in body
Source Link

This is what happens when you take Pascal's Triangle, and color each entry based on the value modulo 2:

Pascal's Triangle modulo 2

The exact code for this is extremely simple:

def drawModuloPascal(n, p):
    for i in range(0, n + 1):
        print " " * (n - i) ,
        for k in range(0, i + 1):
            v = choose(i , k) % p
            print '\x1b[%sm ' % (';'.join([str(0)['0', str(30)'30', str(41 + v)]), ) ,
        print "\x1b[0m" # reset the color for the next row

Just provide your own choose(n, r) implementation. The image above is a screenshot of drawModuloPascal(80, 2).

You can also do this modulo other primes, to get even more remarkable patterns, but then it becomes much less "easy to explain."

This is what happens when you take Pascal's Triangle, and color each entry based on the value modulo 2:

Pascal's Triangle modulo 2

The exact code for this is extremely simple:

def drawModuloPascal(n, p):
    for i in range(0, n + 1):
        print " " * (n - i) ,
        for k in range(0, i + 1):
            v = choose(i , k) % p
            print '\x1b[%sm ' % (';'.join([str(0), str(30), str(41 + v)]), ) ,
        print "\x1b[0m" # reset the color for the next row

Just provide your own choose(n, r) implementation. The image above is a screenshot of drawModuloPascal(80, 2).

You can also do this modulo other primes, to get even more remarkable patterns, but then it becomes much less "easy to explain."

This is what happens when you take Pascal's Triangle, and color each entry based on the value modulo 2:

Pascal's Triangle modulo 2

The exact code for this is extremely simple:

def drawModuloPascal(n, p):
    for i in range(0, n + 1):
        print " " * (n - i) ,
        for k in range(0, i + 1):
            v = choose(i , k) % p
            print '\x1b[%sm ' % (';'.join(['0', '30', str(41 + v)]), ) ,
        print "\x1b[0m" # reset the color for the next row

Just provide your own choose(n, r) implementation. The image above is a screenshot of drawModuloPascal(80, 2).

You can also do this modulo other primes, to get even more remarkable patterns, but then it becomes much less "easy to explain."

Source Link

This is what happens when you take Pascal's Triangle, and color each entry based on the value modulo 2:

Pascal's Triangle modulo 2

The exact code for this is extremely simple:

def drawModuloPascal(n, p):
    for i in range(0, n + 1):
        print " " * (n - i) ,
        for k in range(0, i + 1):
            v = choose(i , k) % p
            print '\x1b[%sm ' % (';'.join([str(0), str(30), str(41 + v)]), ) ,
        print "\x1b[0m" # reset the color for the next row

Just provide your own choose(n, r) implementation. The image above is a screenshot of drawModuloPascal(80, 2).

You can also do this modulo other primes, to get even more remarkable patterns, but then it becomes much less "easy to explain."

Post Made Community Wiki by Adrian Petrescu