Posts Tagged ‘cmy’

More solutions…

May 14, 2009

So mine are almost identical to Tim’s but I’ll post them anyway along with the time they take…

Problem 1:

sum = 0
for i in range(1000):
  if (i%3 == 0 or i%5 == 0):
    sum = sum + i
print sum

Time: 0.000477 sec

Problem 2:

fibsum = 0
a, b = 0, 1
while b < 4000000:    if b%2 == 0:      fibsum = fibsum + b    a, b = b, (a+b) print fibsum [/sourcecode] Time: 0.000148 sec

Advertisements