diff --git a/6/advent_2.py b/6/advent_2.py new file mode 100644 index 0000000..6af729c --- /dev/null +++ b/6/advent_2.py @@ -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)