# HG changeset patch # User Dominic Cleal # Date 1228101275 0 # Node ID fa152d695acd41466b60ea38c7599df916fe729a # Parent 0e08f4decf679abf4453394bd78588d9e241ba02 #50, start of conseq can vary diff -r 0e08f4decf67 -r fa152d695acd problem50.py --- a/problem50.py Mon Dec 01 02:44:16 2008 +0000 +++ b/problem50.py Mon Dec 01 03:14:35 2008 +0000 @@ -1,20 +1,21 @@ import math -def count(i): - c,t = 0,0 - for x in p: - t += x - c += 1 - if t == i: - return c - if t > i: - return False +def count(i, min): + for a in range(0, len(p) - min): + t = 0 + for b in range(a, len(p)): + t += p[b] + if t == i: + return b - a + 1 + if t > i: + break + return False cmax = 0 imax = 0 p = [ 2 ] i = 3 -while i < 1000000: +while i < 1000: isp = True max = int(math.floor(math.sqrt(i))) for t in p[1:]: @@ -25,7 +26,7 @@ break if isp: p.append(i) - c = count(i) + c = count(i, cmax) if not c == False and c > cmax: cmax = c imax = i