-
Notifications
You must be signed in to change notification settings - Fork 0
/
24.zote
37 lines (25 loc) · 889 Bytes
/
24.zote
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
include!("stdlib");
include!("aoc.zote");
input := read("input") >> trim;
lines := input >> split("\n");
low := 200000000000000;
high := 400000000000000;
hail := lines >> map(\>> split("@") >> map(ints));
fn check(((x1, y1, z1), (dx1, dy1, dz1)), ((x2, y2, z2), (dx2, dy2, dz2))) -> {
// Rush to get pen and paper. Time to break out the old lin alg knowledge.
div := dx1 * dy2 - dx2 * dy1;
if div == 0 return false;
t1 := (dx2 * y1 - dx2 * y2 - dy2 * x1 + dy2 * x2) / float(div);
t2 := (dx1 * y1 - dx1 * y2 - dy1 * x1 + dy1 * x2) / float(div);
// Cant int neg time
if t1 < 0 or t2 < 0 return false;
// inside?
x := x1 + dx1*t1;
y := y1 + dy1*t1;
x >= low and x <= high and y >= low and y <= high
}
int := 0;
for (i1, (p1, d1)) in hail >> enumerate for (i2, (p2, d2)) in hail >> enumerate if i2 > i1 {
if check([p1, d1], [p2, d2]) int += 1;
}
print(int);