File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44sys .path .append (os .getcwd ())
55
66from Utilities import primes
7- from itertools import accumulate
87
98def main ():
109
11- prime_numbers = primes .primes_up_to (1000000 )
12- prime_sums_cumulative = list (accumulate (prime_numbers ))
10+ prime_number_list = list (primes .primes_up_to (1000000 ))
1311 # for faster lookups
14- prime_number_set = set (prime_numbers )
12+ prime_number_set = set (prime_number_list )
1513
16- max_consecutives = 0
14+ max_sequence_length = 0
1715 corresponding_prime = 0
1816
19- for s1 in prime_sums_cumulative :
20- for s2 in prime_sums_cumulative :
21- if s1 - s2 > 1000000 :
17+ chain = []
18+
19+ for index , prime in enumerate (prime_number_list ):
20+ sequence_length = 0
21+ total = 0
22+ for sub_prime in prime_number_list [index :]:
23+ total += sub_prime
24+ if total > 1000000 :
2225 break
23- if s1 - s2 in prime_number_set :
24- print ( s1 - s2 )
25- number_consecutives = prime_sums_cumulative . index ( s1 ) - prime_sums_cumulative . index ( s2 )
26- if number_consecutives > max_consecutives :
27- max_consecutives = number_consecutives
28- corresponding_prime = prime_numbers [ prime_sums_cumulative . index ( s1 )]
26+
27+ sequence_length += 1
28+ if total in prime_number_set and sequence_length > max_sequence_length :
29+ max_sequence_length = sequence_length
30+ corresponding_prime = total
31+
2932 return corresponding_prime
3033
3134if __name__ == '__main__' :
Original file line number Diff line number Diff line change 5858 "045" : 1533776805 ,
5959 "046" : 5777 ,
6060 "047" : 134043 ,
61- "048" : 9110846700 ,
62- "049" : "629929699629" ,
61+ "048" : "9110846700" ,
62+ "049" : "296962999629" ,
63+ "050" : 997651 ,
6364}
6465
65- # lambda filter to remove the __pycache__ dir, __init__ file from consideration
66+ # filter to remove the __pycache__ dir, __init__ file from consideration
6667problems = sorted (filter (lambda x : x .isdigit (), os .listdir ("Problems" )))
6768for problem_number in problems :
6869 path = os .path .join ("Problems" , problem_number , "solution" )
You can’t perform that action at this time.
0 commit comments