Monday, January 05, 2009

Neat pattern

Wasn't expecting to see any sort of pattern when testing range operations in Python, this is super cool:

>>> sum(num * num
for num in xrange(1, 10))
285
>>> sum(num * num
for num in xrange(1, 100))
328350
>>> sum(num * num
for num in xrange(1, 1000))
332833500
>>> sum(num * num
for num in xrange(1, 10000))
333283335000L
>>> sum(num * num
for num in xrange(1, 100000))
333328333350000L
>>> sum(num * num
for num in xrange(1, 1000000))
333332833333500000L
>>> sum(num * num
for num in xrange(1, 10000000))
333333283333335000000L

After that it started to take a long time to compute so I gave up.

Labels: , , ,

By al - 12:50 PM |

    follow me on Twitter

    al's del.icio.us Links

    • www.flickr.com
      This is a Flickr badge showing public photos from dragonofsea. Make you own badge here.
    •  
    • (al)



    • Powered by Blogger