completed 2017-01
This commit is contained in:
parent
4505e36b4d
commit
cd651c2812
26
2017/01/2matching-sum.py
Executable file
26
2017/01/2matching-sum.py
Executable file
@ -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)
|
Loading…
x
Reference in New Issue
Block a user