diff --git a/2017/01/2matching-sum.py b/2017/01/2matching-sum.py new file mode 100755 index 0000000..4c0d9f6 --- /dev/null +++ b/2017/01/2matching-sum.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +import sys + +if __name__ == '__main__': + + try: + filename = sys.argv[1] + except IndexError: + filename = "" + + if filename == "": + print("input only digits:") + seq = input() + string = str(seq) + else: + with open(filename, "r", encoding="utf-8") as file: + string = file.read(9999).strip() + + total = 0 + length = len(string) + + for i in range(length): + if (string[i] == string[(i+int(length/2))%length]): + total += int(string[i]) + + print(total)