98 lines
2.6 KiB
Python
Executable File
98 lines
2.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Point:
|
|
line: int
|
|
pos: int
|
|
|
|
|
|
def kasonsymbol(x):
|
|
print(x, end="")
|
|
if x.isdigit():
|
|
return False
|
|
if x == ".":
|
|
return False
|
|
return True
|
|
|
|
|
|
def vaatakast(algus, lopp, andmed):
|
|
print("Vaatame kasti")
|
|
retval = False
|
|
if algus.line > 0:
|
|
if algus.pos > 0:
|
|
if kasonsymbol(andmed[algus.line - 1][algus.pos - 1]):
|
|
retval = True
|
|
for i in range(algus.pos, lopp.pos):
|
|
if kasonsymbol(andmed[algus.line - 1][i]):
|
|
retval = True
|
|
if lopp.pos < (len(andmed[algus.line]) - 2):
|
|
if kasonsymbol(andmed[algus.line - 1][lopp.pos]):
|
|
retval = True
|
|
print()
|
|
if algus.pos > 0:
|
|
if kasonsymbol(andmed[algus.line][algus.pos - 1]):
|
|
retval = True
|
|
for u in range(algus.pos, lopp.pos):
|
|
print("-", end="")
|
|
if lopp.pos < (len(andmed[algus.line]) - 2):
|
|
if kasonsymbol(andmed[algus.line][lopp.pos]):
|
|
retval = True
|
|
print()
|
|
if algus.line < len(andmed) - 2:
|
|
if algus.pos > 0:
|
|
if kasonsymbol(andmed[algus.line + 1][algus.pos - 1]):
|
|
retval = True
|
|
for i in range(algus.pos, lopp.pos):
|
|
if kasonsymbol(andmed[algus.line + 1][i]):
|
|
retval = True
|
|
if lopp.pos < (len(andmed[algus.line]) - 2):
|
|
if kasonsymbol(andmed[algus.line + 1][lopp.pos]):
|
|
retval = True
|
|
print()
|
|
if retval:
|
|
print("Kast kinni")
|
|
else:
|
|
print("Kast lahti")
|
|
return retval
|
|
|
|
|
|
with open("/home/jesmin/wrk/aoc/3/data.txt") as file:
|
|
lines = [line.rstrip() for line in file]
|
|
|
|
linecount = len(lines)
|
|
|
|
x = 0
|
|
y = 0
|
|
kogunumber = 0
|
|
for y in range(0, linecount):
|
|
number = ""
|
|
print("Rida algab")
|
|
print(lines[y])
|
|
for x in range(0, len(lines[y])):
|
|
if lines[y][x].isdigit():
|
|
if len(number) == 0:
|
|
numbrialgus = Point(y, x)
|
|
number += lines[y][x]
|
|
else:
|
|
if len(number) > 0:
|
|
numbrilopp = Point(y, x)
|
|
print(f"Otsime numbrit {number}")
|
|
if vaatakast(numbrialgus, numbrilopp, lines):
|
|
kogunumber += int(number)
|
|
else:
|
|
print(f"Pole number {number}")
|
|
number = ""
|
|
|
|
if len(number) > 0:
|
|
numbrilopp = Point(y, x)
|
|
print(f"Otsime numbrit {number}")
|
|
if vaatakast(numbrialgus, numbrilopp, lines):
|
|
kogunumber += int(number)
|
|
else:
|
|
print(f"Pole number {number}")
|
|
number = ""
|
|
|
|
print(kogunumber) |