blob: 6ec294ffce5c1656aab06dea9d7a59e498ba4021 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/env python3
import sys
def main(array):
score = 0
# Get all unique numbers
for i in set(array):
# Calculate the sum of all numbers one less, the same or one more
# than the target
this_score = sum(x for x in array if i-1 <= x <= i+1)
# Record this score if it is larger
if score < this_score:
score = this_score
print(score)
if __name__ == '__main__':
# Turn the strings into integers
n = [int(i) for i in sys.argv[1:]]
main(n)
|