From cd651c28128806972047be5816f4002bbd4add68 Mon Sep 17 00:00:00 2001 From: dusk Date: Thu, 24 Jul 2025 17:05:56 +0000 Subject: [PATCH] completed 2017-01 --- 2017/01/2matching-sum.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 2017/01/2matching-sum.py 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)