-
Notifications
You must be signed in to change notification settings - Fork 0
/
day6.mar
47 lines (38 loc) · 1.05 KB
/
day6.mar
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
import ../stdlib.mar
fun main(): Never {
var lines = read_file("advent/day6-2.big").unwrap().to_string().lines()
println(lines)
lines.get_ref(0).trim_prefix("Time:")
lines.get_ref(1).trim_prefix("Distance:")
println(lines)
var times = list[Int]()
var distances = list[Int]()
for time in lines.get(0).split(" ") do
if not(time.is_empty()) then times.&.push(time.parse_int())
for dist in lines.get(1).split(" ") do
if not(dist.is_empty()) then distances.&.push(dist.parse_int())
println(times)
println(distances)
var wins = list[Int]()
var i = 0
loop {
if i == times.len then break
var time = times.get(i)
var goal = distances.get(i)
var ways_to_win = 0
for hold in 1..time do {
var speed = hold
var release = time - hold
var dist = release * speed
if dist > goal then ways_to_win = ways_to_win + 1
}
i = i + 1
println(ways_to_win)
wins.&.push(ways_to_win)
}
println(wins)
var product = 1
for win in wins do product = product * win
println(product)
exit(0)
}