day 3-2 wrong
This commit is contained in:
31
03/03-2.py
Normal file
31
03/03-2.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
file = "./ex.txt"
|
||||||
|
#file = "./input.txt"
|
||||||
|
|
||||||
|
def find_num(l:str) -> int:
|
||||||
|
numbers = "9876543210"
|
||||||
|
nums = []
|
||||||
|
pos = 0
|
||||||
|
for zell in range(1,12):
|
||||||
|
|
||||||
|
for n in numbers:
|
||||||
|
if zell < len(nums):
|
||||||
|
continue
|
||||||
|
for i in range(pos, len(l)-11+zell):
|
||||||
|
if n == l[i]:
|
||||||
|
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}")
|
||||||
Reference in New Issue
Block a user