Skip to content

Commit 66cd61a

Browse files
committed
[py] 2023:06: Solve part2
Yes, I just brute-forced this, like part1. It runs in 15 seconds, at 2.7M it/sec, on my CPU, so idgaf
1 parent 6e4fef3 commit 66cd61a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

2023/day06/part2.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import re
2+
from tqdm import tqdm
3+
4+
5+
BASE_REGEX: str = "$$n$$: ([\\s\\d]*)"
6+
7+
with open("input", "r") as input_file:
8+
input_text: str = input_file.read().strip()
9+
10+
11+
def get_values(line_name: str) -> list[int]:
12+
global input_text
13+
regex: str = BASE_REGEX.replace("$$n$$", line_name.capitalize())
14+
search: re.Match = re.search(regex, input_text)
15+
result: str = search.groups()[0].split()
16+
return [int(n) for n in result]
17+
18+
19+
def calculate_distance(windup: int, total: int):
20+
# speed[mm/ms] = windup[ms]
21+
runtime: int = total - windup # [ms]
22+
return runtime * windup # [mm]
23+
24+
25+
time: int = int("".join([str(t) for t in get_values("time")]))
26+
dist: int = int("".join([str(d) for d in get_values("distance")]))
27+
28+
winning_windups: int = 0
29+
for windup in tqdm(range(time)):
30+
reached_dist: int = calculate_distance(windup, time)
31+
if reached_dist > dist:
32+
winning_windups += 1
33+
print(f"SOLVE: {winning_windups}")

0 commit comments

Comments
 (0)