= dirname(@__FILE__);
root = joinpath(root, "..", "..", "DATA", "2023", "input_day06.txt");
input_file = read(open(input_file, "r"), String);
input_data println(input_data)
Time: 58 81 96 76
Distance: 434 1041 2219 1218
Julia Romanowska
The races’ times and distances:
For each race, we can hold the button to charge the boat for varying number of miliseconds but not exceed the maximum time given in the input file. With each milisecond of holding the button, the boat gains 1ms/mm velocity.
We need to find the number of ways we can get larger distance than what is in the input file.
all_winning_approaches = Int64[];
for idx in 1:lastindex(times)
cur_max_time = times[idx];
cur_max_dist = distances[idx];
cur_winning_approaches = 0;
for t in 1:(cur_max_time - 1)
max_dist = find_max_dist(t, cur_max_time)
if max_dist > cur_max_dist
cur_winning_approaches += 1;
end
end
push!(all_winning_approaches, cur_winning_approaches);
end
The total number of ways to win all the races: 1159152.
Instead of the input showing many races, it’s actually one!
The total number of ways to win the long race: 41513103.