File tree 2 files changed +13
-9
lines changed
2 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 26
26
3 nested loops since we know the answer will be 12 digits.
27
27
"""
28
28
29
- from math import sqrt , floor
30
29
from itertools import permutations
30
+ from math import floor , sqrt
31
31
32
32
33
33
def is_prime (number : int ) -> bool :
@@ -107,10 +107,14 @@ def solution():
107
107
for i in range (length ):
108
108
for j in range (i + 1 , length ):
109
109
for k in range (j + 1 , length ):
110
- if abs (candidate [i ] - candidate [j ]) == abs (candidate [j ] - candidate [k ]) \
111
- and len (set ([candidate [i ], candidate [j ], candidate [k ]])) == 3 :
110
+ if (
111
+ abs (candidate [i ] - candidate [j ])
112
+ == abs (candidate [j ] - candidate [k ])
113
+ and len (set ([candidate [i ], candidate [j ], candidate [k ]])) == 3
114
+ ):
112
115
passed .append (
113
- sorted ([candidate [i ], candidate [j ], candidate [k ]]))
116
+ sorted ([candidate [i ], candidate [j ], candidate [k ]])
117
+ )
114
118
found = True
115
119
116
120
if found :
Original file line number Diff line number Diff line change 25
25
Then, use sliding window to get the answer.
26
26
"""
27
27
28
- from math import sqrt , floor
28
+ from math import floor , sqrt
29
29
30
30
31
31
def is_prime (number : int ) -> bool :
@@ -56,20 +56,20 @@ def solution():
56
56
997651
57
57
"""
58
58
59
- prime_list = [2 ] + [x for x in range (3 , 10 ** 6 , 2 ) if is_prime (x )]
59
+ prime_list = [2 ] + [x for x in range (3 , 10 ** 6 , 2 ) if is_prime (x )]
60
60
61
61
cumulative_sum = []
62
62
tmp = 0
63
63
for x in prime_list :
64
64
tmp += x
65
- if tmp < 10 ** 6 :
65
+ if tmp < 10 ** 6 :
66
66
cumulative_sum .append (tmp )
67
67
else :
68
68
break
69
69
70
70
upper_limit_idx = 0
71
71
for i in range (len (prime_list )):
72
- if prime_list [i ] < 10 ** 6 :
72
+ if prime_list [i ] < 10 ** 6 :
73
73
upper_limit_idx = i
74
74
else :
75
75
break
@@ -96,5 +96,5 @@ def solution():
96
96
return answer
97
97
98
98
99
- if __name__ == ' __main__' :
99
+ if __name__ == " __main__" :
100
100
print (solution ())
You can’t perform that action at this time.
0 commit comments