-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday6.jl
60 lines (38 loc) · 1.23 KB
/
day6.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
## Read input
cd("/Users/patricklauer/Documents/GitHub/advent_of_code_2023/")
input = readlines("day6_input.txt")
## Create time vector
time = input[1]
time = replace(time, "Time: " => "")
time = parse.(Int, split(time))
## Create distance vector
distance = input[2]
distance = replace(distance, "Distance: " => "")
distance = parse.(Int, split(distance))
distance_partB = deepcopy(distance)
distance_partB = parse(Int64, join(string.(distance_partB)))
time_partB = deepcopy(time)
time_partB = parse(Int64, join(string.(time_partB)))
## Part A
## loop through all the runs
## loop through milliseconds per run
## calculate distance per time span button holding
## compare with record distance of run
## count up win possibilities
## multiply the win possiblities of all runs
## PartB
## Transform distance and time to one pasted integer
## and feed to the loop described in outline for PartA
## Result Loop
runs = length(time_partB)
wins = zeros(Int, length(time_partB))
for i in 1:runs
milliseconds = time_partB[i]
for speed in 0:milliseconds
dist_achieved = (milliseconds - speed) * speed # Δpushbutton = speed
if dist_achieved > distance_partB[i]
wins[i] += 1
end
end
end
prod(wins)