diff options
Diffstat (limited to 'challenge-210/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-210/sgreen/python/ch-1.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-210/sgreen/python/ch-1.py b/challenge-210/sgreen/python/ch-1.py new file mode 100755 index 0000000000..6ec294ffce --- /dev/null +++ b/challenge-210/sgreen/python/ch-1.py @@ -0,0 +1,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) |
