-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.zote
68 lines (56 loc) · 1.07 KB
/
8.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
include!("stdlib");
include!("aoc.zote");
input := read("input");
(steps, instr) := input >> split("\n\n");
ins := [];
way := dict();
for line in instr >> split("\n") {
way[line[:3]] = [line[-9:-6], line[-4:-1]];
}
poss := [];
for (node, _) in way {
if node[2] == 'A' node >> push(poss);
}
poss = poss >> sort;
part1 := false;
repeats := [];
for pos in poss {
inds := [];
ind := 0;
while true {
step := steps[ind % len(steps)];
done := true;
match step {
'L' -> {
pos = way[pos][0];
}
'R' -> {
pos = way[pos][1];
}
}
ind += 1;
if pos[-1] == 'Z' {
if !part1 {
part1 = true;
print(ind);
}
ind >> push(inds);
if len(inds) > 5 {
inds >> push(repeats);
break;
}
}
}
}
reps := [];
for inds in repeats {
for (i1, i2) in zip(inds[1:], inds) {
i1 - i2 >> push(reps);
break; // Added later since I saw that the pattern started immediately
}
}
// Used for maths to find answer
// reps >> print;
// firsts := repeats >> map(\>> [0]) >> print;
// Found with online mats tools from reps.
lcd := 17972669116327 >> print;