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: Labels: Mathematics, Programming, Python, Sequences
>>> 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.
By al - 12:50 p.m. |