George Sakkis <[EMAIL PROTECTED]> wrote: > On Feb 9, 9:20 pm, [EMAIL PROTECTED] wrote: > > This is a bit simpler, but probably there are simpler solutions using > > modular arithmetic: > > > > l = [1] > > for _ in range(15): > > print ''.join(" *"[x] for x in l) > > l = [1] + [l[i+1]^l[i] for i in range(len(l)-1)] + [1] > > > > Bye, > > bearophile > > Here's another one, adapted from the example (in Java) in Wikipedia's > entry (http://en.wikipedia.org/wiki/Sierpinski_triangle): > > N=15 > for x in xrange(N,0,-1): > print ''.join('* '[x&y!=0] for y in xrange(N+1-x)) >
This is my solution after a few minutes thought. It uses a different algorithm for generating the triangle. If python could output binary numbers it would be more elegant... >>> n = 1 >>> for i in range(16): ... print ("%X" % n).replace('0', ' ').replace('1', '*') ... n = n ^ (n << 4) ... * ** * * **** * * ** ** * * * * ******** * * ** ** * * * * **** **** * * * * ** ** ** ** * * * * * * * * **************** -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list