6. teine
This commit is contained in:
36
6/advent_2.py
Normal file
36
6/advent_2.py
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
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)
|
||||||
Reference in New Issue
Block a user