2023-12-05 10:50:52 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
from dataclasses import dataclass
|
2023-12-05 14:56:37 +02:00
|
|
|
import re
|
2023-12-05 10:50:52 +02:00
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
|
class Range:
|
2023-12-05 14:56:37 +02:00
|
|
|
target: int
|
|
|
|
|
source: int
|
|
|
|
|
length: int
|
2023-12-05 10:50:52 +02:00
|
|
|
|
|
|
|
|
with open("data.txt") as file:
|
|
|
|
|
lines = [line.rstrip() for line in file]
|
|
|
|
|
|
2023-12-05 14:56:37 +02:00
|
|
|
tables = []
|
|
|
|
|
table = []
|
|
|
|
|
seeds = []
|
|
|
|
|
|
|
|
|
|
for line in lines:
|
|
|
|
|
if line == '':
|
|
|
|
|
print('Tühi rida')
|
|
|
|
|
continue
|
|
|
|
|
if line.startswith("seeds: "):
|
|
|
|
|
temp = re.findall(r'\d+', line)
|
|
|
|
|
seeds = list(map(int, temp))
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
if line[0].isalpha():
|
|
|
|
|
if len(table)>0:
|
|
|
|
|
tables.append(table)
|
|
|
|
|
table = []
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
temp = re.findall(r'\d+', line)
|
|
|
|
|
tableitems = list(map(int, temp))
|
|
|
|
|
table.append(Range(*tableitems))
|
2023-12-05 15:09:06 +02:00
|
|
|
tables.append(table)
|
2023-12-05 14:56:37 +02:00
|
|
|
|
|
|
|
|
print(seeds)
|
2023-12-05 15:09:06 +02:00
|
|
|
for table in tables:
|
|
|
|
|
print("tabel")
|
|
|
|
|
for rida in table:
|
|
|
|
|
print(rida)
|
2023-12-05 14:56:37 +02:00
|
|
|
|
|
|
|
|
pisim = 0
|
|
|
|
|
for arv in seeds:
|
2023-12-05 15:09:06 +02:00
|
|
|
print(f"Algus: {arv}")
|
2023-12-05 14:56:37 +02:00
|
|
|
for table in tables:
|
|
|
|
|
muudetud = False
|
|
|
|
|
print("tabel")
|
|
|
|
|
for mapping in table:
|
|
|
|
|
if arv >= mapping.source and arv < (mapping.source + mapping.length):
|
|
|
|
|
print(mapping)
|
|
|
|
|
arv = mapping.target + (arv - mapping.source)
|
|
|
|
|
print(f"Uus arv: {arv}")
|
|
|
|
|
break
|
|
|
|
|
|
2023-12-05 15:09:06 +02:00
|
|
|
print(f"Vastus: {arv}")
|
2023-12-05 14:56:37 +02:00
|
|
|
if pisim == 0:
|
|
|
|
|
pisim = arv
|
|
|
|
|
if pisim > arv:
|
|
|
|
|
pisim = arv
|
|
|
|
|
|
|
|
|
|
print(pisim)
|