Files
Advent2023/6/advent_2.py
Lauri Jesmin b589748e9d 6. teine
2024-08-08 14:49:43 +03:00

37 lines
780 B
Python

import re
with open("data.txt") as file:
lines = [line.rstrip() for line in file]
times = []
distances = []
for line in lines:
if line == '':
print('Tühi rida')
continue
if line.startswith("Time: "):
temp = re.findall(r'\d+', line)
times = list(map(int, temp))
continue
if line.startswith("Distance: "):
temp = re.findall(r'\d+', line)
distances = list(map(int, temp))
continue
print(times)
print(distances)
x = 1
for attempt in range(0, len(times)):
waystowin = 0
time = times[attempt]
distance = distances[attempt]
for i in range(1, time):
if i * (time-i) > distance:
print(f"Võidan, {i*(time-i)}")
waystowin += 1
x *= waystowin
print(x)