30 lines
815 B
Python
30 lines
815 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
import time
|
|
#file = "./ex.txt"
|
|
file = "./input.txt"
|
|
start = time.time()
|
|
|
|
def find_num(l:str) -> int:
|
|
numbers = "9876543210"
|
|
nums = []
|
|
pos = 0
|
|
for zell in range(0,13):
|
|
while zell > len(nums):
|
|
for n in numbers:
|
|
for i in range(pos, len(l)-12+zell):
|
|
if n == l[i] and zell > len(nums):
|
|
pos = i+1
|
|
nums.append(n)
|
|
# print("".join(nums))
|
|
return int("".join(nums))
|
|
|
|
if __name__ == "__main__":
|
|
solution = 0
|
|
input_file = open(file, "r")
|
|
for line in input_file:
|
|
line = line.strip()
|
|
if line == "":
|
|
continue
|
|
solution += find_num(line)
|
|
print(f"Solution: {solution} benötigte Zeit:{time.time()-start} s") |