changeset 1:fa152d695acd

#50, start of conseq can vary
author Dominic Cleal <dominic@computerkb.co.uk>
date Mon, 01 Dec 2008 03:14:35 +0000
parents 0e08f4decf67
children b94533a8c529
files problem50.py
diffstat 1 files changed, 12 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- 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