File tree 4 files changed +41
-0
lines changed
solution_05_1_passing_cars
4 files changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ Codility exercise 05.1 PassingCars
3
+ """
4
+ from solution_05_1_passing_cars .solution import solution
5
+
6
+
7
+ def main ():
8
+ """
9
+ Main function calls solution for codility task 05.1
10
+ """
11
+ while True :
12
+ try :
13
+ array = list (map (int , input ('Enter int array with 0 or 1: ' ).strip ().split (' ' )))
14
+ print (solution (array ))
15
+ except ValueError as ex :
16
+ print (f'Wring input! { ex } . Try again.' )
17
+ continue
18
+ except KeyboardInterrupt :
19
+ return
20
+
21
+
22
+ if __name__ == '__main__' :
23
+ main ()
Original file line number Diff line number Diff line change
1
+ """
2
+ Solution for exercise 05.1 PassingCars
3
+ """
4
+ from itertools import accumulate
5
+
6
+
7
+ def solution (a ):
8
+ suffix_sum = list (accumulate (reversed (a )))
9
+ counter = 0
10
+ prev = suffix_sum [0 ]
11
+ for value in suffix_sum [1 :]:
12
+ if value == prev :
13
+ counter += prev
14
+ else :
15
+ prev = value
16
+ if counter > 1000000000 :
17
+ return - 1
18
+ return counter
You can’t perform that action at this time.
0 commit comments