aboutsummaryrefslogtreecommitdiffstats
path: root/day13
diff options
context:
space:
mode:
authorAn0nSaiko <porfeas12@gmail.com>2022-12-13 21:51:55 +0200
committerAn0nSaiko <porfeas12@gmail.com>2022-12-13 21:51:55 +0200
commit479a4664be5a7c0a971726dca919e6fc0849e6b7 (patch)
treebcba201c0ce204b01a8397b5edd4279d38dffe64 /day13
parentDay 12 (diff)
downloadaoc22-479a4664be5a7c0a971726dca919e6fc0849e6b7.tar.gz
aoc22-479a4664be5a7c0a971726dca919e6fc0849e6b7.zip
Day 13
Diffstat (limited to 'day13')
-rw-r--r--day13/example.txt23
-rw-r--r--day13/input.txt449
-rw-r--r--day13/solution.nim121
3 files changed, 593 insertions, 0 deletions
diff --git a/day13/example.txt b/day13/example.txt
new file mode 100644
index 0000000..af73fbb
--- /dev/null
+++ b/day13/example.txt
@@ -0,0 +1,23 @@
1[1,1,3,1,1]
2[1,1,5,1,1]
3
4[[1],[2,3,4]]
5[[1],4]
6
7[9]
8[[8,7,6]]
9
10[[4,4],4,4]
11[[4,4],4,4,4]
12
13[7,7,7,7]
14[7,7,7]
15
16[]
17[3]
18
19[[[]]]
20[[]]
21
22[1,[2,[3,[4,[5,6,7]]]],8,9]
23[1,[2,[3,[4,[5,6,0]]]],8,9]
diff --git a/day13/input.txt b/day13/input.txt
new file mode 100644
index 0000000..0a51f7b
--- /dev/null
+++ b/day13/input.txt
@@ -0,0 +1,449 @@
1[[],[[[0],[8,10,2,8],[4]],[[7,7,2,2],10,1,2,[]]],[[[6,1,6,8,10],[8,6,4],[],[],2]]]
2[[[[]],9],[]]
3
4[[8]]
5[[10,[6,3,[1,7],[4,4,2,7],[1,10]]],[[[5,5,7,9,1],3],[],[],2,3],[3,3,[1,[]],2],[2,10,6,[3,[],[],[1]]]]
6
7[[[0,[0,7,8],5,[8,2,7,8]],10,1,4],[5],[10,[[],8,6,[5,8,9],3],[4,8,[3,3,2],[6,2,3,8,8],[10,10,2,5]],8,0]]
8[[7],[7]]
9
10[[4,[1,[8,8,6,9],[2,10,3],[3],[0,10,9,0,7]],[3,[4],2,3,4]],[[[6,4,1,7,5],10,[9,7],2],[0],9,0,1],[[7],[7,[6,0]],5,10,9]]
11[[],[3,[],0,[7,[3,2,4,7],[10,2,2,2],[1,1,6,3]]],[5,8,[[3,0,7,8,3]],[[3,2,0],8,10,1,1],3],[[6,[],[10,9],3],[],10]]
12
13[[1,[[3],[8,7,4]]],[[[6,10]],2],[[10],8],[2,[]]]
14[[[[3,10],[2,6,6,0,0],1,[],10],[[10,4],[3,6,10,5]],4,[[8,4],7],2]]
15
16[[9,7,3,[[10,9,3,5],[1,8],9,[9,2,6,7,6]]],[2,0,8,[[6,1],[4],6,[4,10,9,6],[]],[5,[],0,[2,0]]],[],[3],[[4],10,[[3,5,10],3,[10],[3,8,2,5],[7,9,9,1]]]]
17[[[3,[3]],[0,[1,3,6,10,3],[],[7,2,7,7,6]]],[[]],[1],[]]
18
19[[],[9,0],[[8,[],[9,1,0],7],2],[]]
20[[[[3,2,4,1,8],3,1,[0,7,4,0,6]],9,[4],[]],[],[[[9],[],[9,10,4,0],[],8],[7,[9,7,2,3]]],[[]],[]]
21
22[[[9,[7,2,0],2,[],[2]],[9,[1],10,[0,9]]]]
23[[6,8,[8,[],[2],[7,3,2]],9,[]],[8,[[3,4,7,5],0,[]]]]
24
25[[[3,8,0,8,[4,7,8]]],[3],[2,7]]
26[[[[9,4,10,5,5]],[[8,9,1,4],[],[7]],[7,[9,6],[2,3],1,[3,1,10,3]]],[9],[[]]]
27
28[[[[5,10,1,7],3,[7],[7,9,4,3],1],[[3,1]],[[],[3,10,3,6]],[6,[10]]],[10,[[5,2,2,4,8],4,[],[9,7],0],0,[0],[7,[4,5],[0],[2,2,5],5]],[2,10,5],[[9,6,1],8,[10,10],[[5,9,7,6],8,0,0,[10]],[[0,0,7,2],[],[5,0]]],[7]]
29[[0,[],3]]
30
31[[[0,[5,9,0,8,7],[5,2],2]],[5,2,6,[[]],9],[[10,6,10,[8,5,0,6,6],[]],5,[[4,0],[10,0,6,6],1,7],[[0,3,0,9,8]]],[[],3],[8,4,3]]
32[[[[4,6],[],8,[],[6,9]],[[9,3,8],10,[2,10]],2]]
33
34[[],[0],[[5],[[2,9],[6,9,8],6],[[3],[7,6,9,8,6],0,5],0,10]]
35[[[[],8,4,[1,0]],[2,6,2,[4,7,10,0]],0,[[3,4,8],2,4],6],[9,3,2],[[[2,10,10],[],2],10,0],[[[9,4,8,10]],[4,[5,10],4],[2,7,[7,5,3,8,9],[9,7,10,7,7]],0,3]]
36
37[[[4,8,6],[0,3],2,4]]
38[[[4],[],6,3,3],[],[[7,[6,2,1,2,0]],[8],[1,[1,5],8,[5,10,10,10]],[7,[6],3]],[],[]]
39
40[[[],[[7,3,0,3],[2],[0,4,2]],0,9,[[6,6,3,0]]]]
41[[[[],[9,5],[0,1,9,2],10],[],2,[7,10,[10,5,10,1],8,[]]],[4,[8],4],[1,9,2,10]]
42
43[[[5,7,5],7,[2,7],9]]
44[[[[6,0,7,6],6],[3]],[],[[[9,6]],5,[[10,7,4]],[],[5]],[7,[[7],[6,9,0],8],[[9,0,9]],[]]]
45
46[[],[[[],[],[3,4],3]],[[5,[10],7,8],3,[[8],5,[3,2,1],[8],8]]]
47[[[2,3,2]],[],[[[],[4],[]],3,2,[[6,10,7,6,6]]],[[],10,0,4]]
48
49[[[0],[4,9,3,[2],[10,2,3,3]],[1],3,[9,6,[5,5,4,7],6]],[]]
50[[[10,3,9,[3,2]],[3],9,[[],10,4,[5,3,7,0,1],8]],[]]
51
52[[10,[4,2,[],0],[5,[2,6,6],[4,8,7,7,8]]]]
53[[3],[],[10,[[2,8,2]],1,5]]
54
55[[5]]
56[[6,9,[3]]]
57
58[[6,[5,[7,10,4]],3],[[[8,0,4,0,4],[6,6]],4,[[],[2,0,9,10,4],10,6,1],[[3,10,5]],8],[3,5,[5,9,[],7],[7,[8,3,4],[1]],[[1,6]]]]
59[]
60
61[[],[[9,[10,4,7,0],1]],[9,2],[[[8,6,10,6,8]],[9],[[8],[1]]],[6,9,2,[],[[4,3]]]]
62[[],[[],[[8,6,1]],0,1,0],[[[2],[6,10,10],9,2],0],[8,[[10]],4]]
63
64[[[[9,3,0,8],[5],[7,10,6,10,2],[]],3,9,[]],[9,4,[]]]
65[[9,[[6,3,9],5],6],[9,8,[2],[]],[7,7,[3,[],[4,5,2],[5],6],1,[[0,0,0,0],1,[0],[0,2,0,9],[5,3]]],[6,4,[],[],7],[[],5]]
66
67[2,5,4,1]
68[2,5,4,1,4]
69
70[[[0,2,6,7],[[4,3,4,2],5,4]],[1,[10,0],[[9,6,1,4],5]],[2,2,[10,8],[8,8,0,[5,0,10,2,6]],9],[7,[0,[],[]],4],[[[6,10],6,[7,2,10,9],0,[]],6,7,[[10,4,5],[8,8],[1,6,10,5,9],[3,6,1,4]],3]]
71[[[[2,0,9,2],3,6,[3,1,3,6]],[]],[[],0,[[8,4,4]],8,[]]]
72
73[[[[5,0],[7,8,4,8,5],5,8,[4,1,0,5,10]]],[]]
74[[5],[[[],[1,2,2,4],3,1],1]]
75
76[[0,2],[],[4,[9,[1,6,7],4,[10],[2,0,7]],[],[8,2]],[[[2,4,0],2]],[4]]
77[[[8,[6],9,0,6]],[10,[],3,10]]
78
79[[[],1,6,8,[10,[2,4],[1,8],7]],[],[6,[[2,9,3,6],[3,4,3,4],[10,7,2,8,6]],10,8,6],[[5]]]
80[[[5,[8,6,10,8],[4,7],[6,10]],3],[[[1,6,7],[2,3,3,6,2],7,6],[[0,5,0,3],[7,5,7],[7,7,3],[6,10,1],[10,10]],0]]
81
82[[[7],8],[[[8],[7,1],[5]]],[5]]
83[[[7,[3,8]],0,[6,[6,9],[5,9],[1,3,6],4]],[4,4,[1,[5,7,10,2],4,6]],[3,0,10],[9,6],[[[3,1],0,[],0,[8,2,9,0,1]],6,10,[10,[6,8,8,0,10],[]]]]
84
85[[[1,6,1,[7,4,5],[0]]]]
86[[[9,[0,9],[7,3,0],2],3,7,3],[[[5],3],8,[[5,5,9],7],7],[6,5,[[3,4],[2,9,10,3],1,[3,3,0,7,0],1],[6]],[6,[]]]
87
88[[9,5,[],5,9],[[[1,6,8],[3,6,0,10,2]],3],[9]]
89[[[9,3,[2],[8,6,2,5,7],[9,4,1]],[[5,0,3],10,6,10,5]]]
90
91[[[[7]],[]],[10,[10,2,9,2]]]
92[[[4,4],[[0,0,7,6],[4,8,6]],0],[5,4,0],[7,[],[1,3,[7]],3],[[8,[1,0,5]],[7,[],1,1,9]],[4,[10,[2],[6],4],[[5,4,9,3,4]],[10,[10,4],0,5],6]]
93
94[[7],[10,3,[],9,[[],9,[7,9,0,5,2],[10],[10,6,6]]]]
95[[[[3,1,1,9,5]],[],8,[1,10,[2,7,1],3,5]],[],[[[6,8,6,8,0],1,8],8,6,[[6,10,1,8],10],[1,[],[],[10]]],[]]
96
97[[[[3,6,1,3,0],[6],[1,2,6]],[[9,8,7],2,[9,0,8,4]]],[[6],1,6],[9,8,7]]
98[[[[0,4,0]]],[[6],10],[[[6],[5,2,1]]],[],[7,[3,[3,8]]]]
99
100[[[[8,9],[4],5,3],[[9,2,2],10,[0,2],10],1,0],[4],[[1,[5,2,2,5,5],6,[9,4,6,3,5],8],10,4,[],[[3],[2]]]]
101[[2],[[9,2,[9,5,7],4,1]],[3,0,[[],[10],0,[10,8,6,6],[10,9,7,1,4]],[8,[1,4,2,5,6],1,7,2],7]]
102
103[[],[[],4,[[0,4,9,6,6],4,[],5],[[2,7],[10,2],[0,6,0,2]],[5,[2,10,10,7],8,1,[1,2,4,9]]],[[7,6,1],6,[[],0]],[10,3,[4,[]]],[[[5],2,10],10,[[9],[1]],[7,2,[6,6,10,5,8],[6,0,3,4,10],9],[1,[9,0],[7,2,10,8,9],10]]]
104[[[10],[[7,6,10,7,6]],0,[],1],[[[2],1],1,[6,3]],[[[9,0,6,6,1]],9]]
105
106[[[[],[2,10],1,0,0],[[2,6],4,8,[8,10,2,7,1]],6,[5,4,7,9,[10]],[[9,6],10,[6,7],9]],[2,[10],2,3,9],[[[0,5,4,5],6,[8,9,8,0,4]],[1]]]
107[[],[[[3],5,[2,8],[9,7,0],10],7],[[],1,[[10,3,10,8]],2,9]]
108
109[[0,7,[7,4,[8,3,10,5]],[7,[9,5,5]],[[1,9,7],2,[4,6,7,6,8],[6,6,3],10]]]
110[[[3,6,10,[10,8,2,2,6]],[8,[1,6,1],1]]]
111
112[[],[1,5,[[2,3,2]],[],9],[[4],7,[5,[5]],6,[[9,5,10],[9],[]]],[1,1]]
113[[],[10,9]]
114
115[[],[[[9,2,4,5],5,[3,9,2,5,3],[3,9,3,4],[]]],[],[1,10,[]],[3,[8],[10,3,[5,2,0],[5,8,1,6,6]],[[10,7,4,8,2],5]]]
116[[[[6,9]]],[[[8,1,1,0]],[8]],[9,[[0,6],1,0],3,[[4,8,6]]]]
117
118[[[4,[6]],[[10,10,8,9,8]],[[3]],2,[[3,9,7,4]]],[[],1,1],[]]
119[[[]],[9,10],[]]
120
121[[6,[]],[3,0,1,[],[[2,1,5],[6,3,8],[9]]],[7,9,[]],[4,[[0,0,8]],6,4]]
122[[],[],[[[1],[3,7],[4,1],[9,10,5]]],[2,[],[[10,5],[4,1,5,9]],3],[[[10,3,8],[3,4,8,6],[7,6,2,4,0]],5]]
123
124[[[[6,3,2,2]],9,8],[10,3,[8]],[[9,[],[],7,[7,7,2,5]],[[0,6],5,10,7,[0,6,0,7,7]],[[3,6,10,6,4],0,7,8],[],[6,6,[],6,[6]]],[[[10,4,8]],[],[4,[3,6,0,9,4],4],0,[]],[10,7]]
125[[10,8,8,[[6],4]],[2,[0,0,8,[8,8]]],[[[7,3],[7],0,[5,3,7,9,1]],9],[7,[[6,2,3],[3,9,2,7],[],2,1],4,[]],[5,[6]]]
126
127[[1,1,7,5],[[[5,8,8,9,10],[8,9,0],[1,9,9,3],0,[5,10]],[[3],7,[6,8],[4,3],5],4],[[[3,5,1],[6,5],1,[4,4,10,9]],[],3,6,[]],[7],[[4,9,[9],[3,2]],7,10]]
128[[9,[[6,1,6,3,9]],[[1,2,6,3,0],[3,5,10]],8],[4,[[1,7,4,8],4,9,[5,5,10,0],[5,7]],0]]
129
130[[1,[10,[6,1],5]],[7],[],[4]]
131[[7],[5,10,6,[0]]]
132
133[[[4,[9,5,5],8],[],[4]]]
134[[[3,[4]]],[2,8,8,[9],[0,[2,7,4],4,7]],[10,6,7],[[[],0,[],[10,10,9,8]]]]
135
136[[3,[2,2,[3,2,1,6,2]]],[2,5,[3],[2],10],[5,[[8,9,2,2,7],[7,6,6,1,7]],8]]
137[[],[0,[4,[4]],9,5],[4,[10],[],[2,[],[10,4,8,5,5]]]]
138
139[[7,6,[6,3,[5,3,2,4],[3,3],[5]],9],[3,[9]],[[],[5],4,1,[[1,0,2,5],4,10]]]
140[[[[6,6,6],[9,10],1,8,[7,9,4,1,2]]]]
141
142[[3,[[5,5,4,4]],[7,[6,2,9,8],[6,4,8,8,0]]]]
143[[4,0,[[8,2],9],[0,8,[6,7,10,4],[2,1]],0],[[9,[0]]],[8,[1,[4,8,3,1,2],[7,10,8],1,[10,4]]],[4,10,1],[4,[],10,0,10]]
144
145[[[0]],[]]
146[[0,[[],8,[3,5,3],3],[],[[4],1,[8]]],[7],[[[2,4,4,0,3]],[[5,1]],[],[5,9,[4,2,1,6,4],2]]]
147
148[[[[4,9],[5,4,3,1,3],3],10,3,1,[2,[0,1],[4,10,4,6],1]],[9,[10,6,[8,9,2,10],[3,6,7,8],0],1,5]]
149[[[5,[10,8,10,10],[5,1,7,7],[]],5,4]]
150
151[[6,[[]],3,[[5,7],1,10,1,[2,6,7,8]]],[9,4,[9,[1,3],4]],[7,6,[]],[[8,[9],[2,3,2],[1,2,6],7]],[]]
152[[],[7],[[[1,2,10],1,[10,10]]]]
153
154[[[7,3,5,3,[5,6,6,8]],1,[6,[3,1,4]],[[1,7,6,8]],[2,0,7,7]]]
155[[7,[5,[9,1,8,6,1],4,6],9,9],[2,2,[[3],0],1,[[3,4,7],10,[9,1,9],8]],[],[9,7,[[2],6],[3,[7,6,9,8],3,[]]]]
156
157[[6,[[9,10,8],[2,4,5],3,[6,3,4,5],[9,1,3,8]],[[],9,7],[[4,3],[],9,8],[6,4]]]
158[[[10,[3,6,2],7,[]],[[]],[],[[7,10,6,5],0,4,[4,5],6]],[[3]]]
159
160[[[[5,5,9,9,10],[]],7,10],[[[6,5,9,9],[4,0,2]],5]]
161[[[2,[8,6,8,8],[],[6,2,6],[7]],2,2,0]]
162
163[[[8,6,5],[1,[],8,0],1,[0,0]],[[]],[]]
164[[3]]
165
166[[8,9,[[0,1,4,4,0],[],5],6]]
167[[0,1,9,[0,3,0,2],[3,5]],[[[],[0]],[[7],4,[1,5,6],[2,8,8,5]],0],[[4,0,9,[6]],8,[[10,2,6],7,8,[8]],0],[[[8,1,2,0,3],5],7,[[7,4,6],[8,5,6]],[[],2,[]]]]
168
169[[1,6],[[[10,2,2,4],[6,6,2,8]],1,9,7,[9,[6],1]],[7,[[3,0,6,3],[7,10,1]]]]
170[[[0],[[3,8,8,3],9,7,[1,10,9,8,7]],[1,2],1,[0,2,[5,4]]],[]]
171
172[[0,[[0,3,4,6,1],[],[0,1,0],5]]]
173[[[8,[5],9],3,[6,[0,10,5,2,10],[10,2,7,1,7],10],4],[[],[[2,5,1],[],9,[4,6,1,6,10],[5]]],[[[6,0,1,4,10],[3,4,0,1,3],[10,8,4]],5,10],[[[6,3,1,8,8],[5],[5,5,6],6],[[2,1,6,1,8],[],4,4,[0,9,2,4]],[[6,9,2,0],0,8,[6,4,4,1,3],2],5,[[5],2,7,[],2]]]
174
175[[],[2,[3,6],[9,10,8,[10,4,8,3,3]]],[[[7,7,1],3,1,[3,2,6]]],[10,5,[5,[6,2],[3,7]],[10,8,[9,4],[3,2,7,1]],2],[[9,2],[[4,3,4,7,8],[9,6,10,4],3,[7,2],10],1]]
176[[4,[2,8,8,0]],[[5,[],[7,6],[],8],[6,[1,6,9],10],2,[]],[10,6,[]]]
177
178[[4,2],[7,[],[3,3,3,4],8,[]],[9,4,[[0,10],2,[8,10,2,6,3],8,6],8,[4]]]
179[[[0,[4,0,7,9],[10,4,9],2],2,2],[[[],[1],[8,4,2,8],5,[3,8,0,2,8]],6,[9,3,10,[1,5,8]],2,0],[8,[[6,3,8,1,4],[4,7],3],6],[[8,[2],3],[[7,5,6,10,9],9,10],8,[3,[10,0,9,1,3]]]]
180
181[[[1,[3,7,1,5,3],2],[7,0,7],10],[1,[[],7,6,5,0]],[1,[7,[4,5,1,0,10],[2]],7,[],[[10],[9,4,10,7],5,[6]]],[[10,3,2,1,[10,1,2]]]]
182[[],[9,[5,2,7],[[1,0],[8],1,3,[9]],[]],[],[[9,10],10,5,[]]]
183
184[[1,6,[[10],2,[],[],[5]]]]
185[[[8,[5,2,7,1,3],6],2,[[],[9,8]]],[1],[3,2],[[8,6]]]
186
187[[1,[[10,3,9,3]],[[5,5,1,7],5]],[[8,8]],[[[4,1],9,[5,5,7]],[[0,9,9,10],[5,6,2,4,6]]],[9,[1],5,[[2,8,4],9],0]]
188[[7,[5,[10,2,3],5,[6,2,10,8],[1,4,5,7,10]]],[],[[8,3],[[5],[6,4,0,4,4],[9,4,10],[]],9,5,[[6]]],[]]
189
190[[9,1,8,[[8],0,[6,10],5,[9]],[[],6,2]],[[],5,[],9],[0,6,7]]
191[[[[5,7,7,6,2],[2,5,0],9,1],1,[8,[2,8],4,1],10,[1,5,[],[1,8,6,5]]],[[9,3,2],0,[[4,0,5],[10]],[[1,2,5,10],6,[],[10,1,5,10,8]]],[7,[0,3,8,[0]],[],3],[],[6,[6,1,6,5],[7,[4,8,9],1]]]
192
193[[[[4,2,3,4],[],9,7,[0]],8,3],[3,2]]
194[[5,[5,10,[7,0,6,10],[],[1,8,9]],1],[6,5],[5,[1,[9],7,10,[5]],1,[4,[3,7],[0]]]]
195
196[[[]],[[[3,9,9,1],[0,5,0,2,5]],7,3,[6,8],[6,2,[2,10,8],[5,6,7,7,7]]],[2,[[3,3,7,2]]],[[8,[]],[[3,7,0],7,[10,8,4,1],4],2]]
197[[[9,[3,9,4,2],7],2,[0,8,[1,10,9]]],[[9],6]]
198
199[[6,5,[0,[7,3],6],9],[]]
200[[[[0,3,1],[],[6,0,4,0]],10,1],[0,[4,[7,9],10,[0],2]],[0,7,3],[[8,[6,8]],8,7],[6,10,[[7,9,3,0],[0,3],[4,8,2],[7,4,3,0,4]],8]]
201
202[[[[2,3,9,10],5,4,9],[],[]],[[],3,[],1],[[[0]],[[]],5,4,[[5,8,0],[7,2]]]]
203[[7,[],6],[2,9,[[0,0,1],5,[0,3,3,10,8]],[[2,4,7,1,1],[]],2]]
204
205[[[5,10,6,[]],[5],10,[[3,7,10]],1],[1,[6,7,[9,7,4,6]],[[1,5],[3,10,2,0,7],[10,1],9]],[]]
206[[[[3,6,5],[4,9],[9,0,8]]],[3,[[9],[8,3]]],[[8,8,8,[6,1,9,10]],[10,[10,0]],[],9]]
207
208[[8],[],[0]]
209[[[2,1,1],9,1],[[0],3],[[[0,4,7,6,4],4,3,10,1],6,[[5,2,10,3]],[[2,10],[10,3,0,5,4]]],[[[4,0,4,1],[1,10,1],3],[2],[1],8]]
210
211[[8,[2,6,9,6,[10,1,0]],[[4,2,2]],[10,[],[10]]],[0,[[5,1,8,1],4,7,[]]],[9],[7,4,3,6]]
212[[[1,8,[10,2,1,5,2],[7,1,4],6],[[8,5,7],[8,7,6],2],10,[8,[5,3,2,5,3]]],[8],[0,[4,[6],[1,7,3],[7,5,0]],[],9],[]]
213
214[[],[10,[],[]],[[],0,4,7],[2,[],[]]]
215[[[3],[[7,6,5],1,6,2]],[7],[[10,9,6,[7,1,10,8]],[[],[3,8,7],[3,6,1],[],[8]],[1,[7,10,8,4],2],[[1,7],5,[5,7],2],3],[1,[10]]]
216
217[[9,10,1]]
218[[6,6,[[5,0],[5,1,7,2,4],[],9,[3,7,10,5,5]],8],[0,[[8,3,7],10,9],[[8,1,0],[10,6],[2,3],[5],[5,9,8,5,1]],[[1,7,2,1],[4,5,9]]],[[[8,3,0],[10]],2,[5,[7,8,2,5,8],6,2],2],[[4,[0,9]],[[5,6,3,10,5]],[[0,1,0,3,5]],[2,2]]]
219
220[[[1,[1,5,3,3],2,[8,6],[8,4,0,7,9]],5,4,0],[[4,[1,2,10],[1,8,3,10,10],[8,0,10,10,0]],[7,[9,3]],[[6,7,9,10,10],4],[[3,3],7,[],[],[]]],[]]
221[[[[1],[3,1,4,3],0],1,[5,6,9,[9,6,2,8],8],0,5],[3,[],[6,0,[3,8,10],4,[]],[5],5],[[[5,3],3,[],10],[[5,4,1,10]],4,[7,[6,3,2],[3,10],8,9],[4,4,8,[5,4,0,0,5],[4]]]]
222
223[[0,[[10,2,1,4],10,8,6,5],[[1,0],4,0,6],1],[[],[[1,9,3],4,[5,6,1,1],[7,0,4],[4]],[10,7,10,[0,5],8]],[[[5,10,3],3,[1]],[2],[9,3,5,7],0,[]],[2],[]]
224[[[[9,7],4,[3,5]],3,2]]
225
226[10,2,6,5,0]
227[10,2,6,5]
228
229[[[7,5,0,9,[10,4,4]]]]
230[[]]
231
232[[4,[[9,3,1],10,[],10],[],10],[],[9,[],[7,[2,8,8,7,6]],8],[],[[1,8,4],[[8,1,10,7],[6,9,0,3,3],[6],[1]],9,[[5,6],4,5,3,0]]]
233[[[1,[6],[],[9,8,4],10]],[[4,3,5,3],[1,[8,0,5,6,3],[],1]],[[[2]],[7,[7]],[0,4,[4,3,0,9,5]],[2,0,[4,9]]],[6,[[1]],3,6]]
234
235[[[[7,10,4],0],[[0,0,10]],[[10],1],8,1],[[[],[5,2],2],[[10,1,5,5,3],[9,10,4,0]],7,4,[[]]],[5,0,[0,[10],[8,1,2],7,[]],[[1,3,7],7],5],[0,[],[6,10,6,7],[0]]]
236[[5,[8,0,3,3,[]],[[6,9,9,9]],9,[[5],5,[2,7,10,3,2],[10,8,9]]],[],[[]],[[[],[10,5,8,0,8],0],[[10,0,3],[10,4,8,8,5]],[[0],[1,0,9]]]]
237
238[[[[7,5,9],[4,5],1],[2,[9,7,7,5,4],[]],9],[]]
239[[4,[7],1,9,7],[0],[10],[[5]]]
240
241[[[10],4,[[10,2],9,6,[1,9,8],1],10,[[],2,6,8]],[],[2,3,[[],0,[2,4,8,10,10],8,[4,10,6,6,0]],[3],[8]],[1,[[9,3,5],2,[10,6,5],5],[],[]],[1,[[3],[],3,10],[[]],8,5]]
242[[[[8,0,4,5,6],[5,3,10,4,0],[0]],[]],[],[[[5,6,7,0,3],6],5,10],[[5,1],[],[3]],[[8,[10],10,7,8]]]
243
244[[],[3,[[7]]],[4,10,[0,[7,5],10],[6,7,[9,1,3]],[[3,0],9,[3,7,8,7],[],[9,7]]]]
245[[[[]],[[4,5,3],3,[6,2,3]]]]
246
247[[4,10]]
248[[],[],[6],[]]
249
250[[4,3,[[1,8]],5,8],[[],[9,[2,8,4,6,0],[8,10,4,3,5]],[],[3,[0,7,1,7,8],5,[9]],0],[[10,[7],[2,2,5,1,9]],4],[1,[[10,6,9,3,7],1,6]]]
251[[2,8,9,8,6],[2,[10]]]
252
253[[[9,6,1],9,9,7]]
254[[7],[3,[6,3],2,[10]],[[[],[4,7],4],[6,[3,5],[8,0,6,7],[9],6],[[1,2,4,10],[],[0,7,2,1,5]],10],[4,[[7,8]],0,[2,7,[10,6]]]]
255
256[[],[],[1,[[],5,3],8,[[8,6],[],1,4,[6,10,8,6,0]]],[],[[4,0,[],5],[[5,8],1,5],6,3]]
257[[],[6,[[2,9],3,[8,5,8,8,9],[6,5,6],4]]]
258
259[[9],[[[4]],10,[[10,1],[6,4,1,6],1,[3,9]],[[4,1]],8],[0,[]],[[[],[0,1]]]]
260[[],[[6,4,[6,1,8],[8],6],5,6,[[7,4],[],[0,4,1,2,7],[2,6]],[[],[]]],[[6,[7,3,2,3,10],2],7,5,4],[5,[0,7]]]
261
262[[[[0,8,3,2,0],7,[],[3],[1,3,9]],[],1],[[3,[6,3,2,5,7],6,2,[2,8,6,0]],[[9,0,2,5],3],[[],10,2],10]]
263[[2],[9,8,[]]]
264
265[[[6,1,[4]],10,10,[[3,1,0],2],[0,4,3,[2,2,5,7]]],[1,3,3],[[10],[2,3,4,0,4],6,[[],[1,7,2,6,8],5]],[0]]
266[[],[[3,[4,3]],[0,[9,7,8],[9,0,4,5],8],5,4],[9]]
267
268[[10,[6,[2,1,1],[10,0],[],0],[7,[7],5,[9,4]]],[[],10]]
269[[[[10,9,1,9,3]],[7,[7,0,10,2],3,[3,6,1,1,6],[6,9,3]],[[1,4,0,10],[0],0,[1,9,5],9]],[],[0,3,[0],9]]
270
271[[[[]]],[[10,10,10],[[8,9,6,4,1]],[[5,0,4,7],[5,4,1,7],3,9,[8,10]],[[9,0,9],7,2,9],[[6],[0,7,10,2],[5,6,10],[5,8,5],1]],[[4],[[],[7,2],[9],[9,0,8,3,10]],10,[4,7,3,3,[1,9,4,3]]],[1,2]]
272[[8,4],[[],7,7],[[[10,1],[7,5,7,0]],[[3],[2,3,3,6]]],[[9,6,5,5],3,[1,[10],9,[6]],5,3],[[],[8,4,3,3]]]
273
274[[[[0],6,7]],[9,[[7,0,0,3],[5,2,1,9],[5,4]],[2],[10,[10,3,10],[5,0],[10,0,6],7],6],[5,[4,[],3,[5,9],[]]],[[]],[]]
275[[[0,[6,1],[6,1,5,4,4],[0,7,2],2],[[3,8,6,10],4,[8,2,2]],3],[[[10],[9]],[10,[2,9,5,1],5,3],10,[5,[9,3,1],5,[7,2,10,4,6],[9]]],[[2,[2,5,7]],5,7],[7,[]]]
276
277[[4],[8],[[],8,[[10,8,6,6,1]],[4,1,[0],[1]]],[[2],1,[[4,0,7],[],[0,7,4,1]]]]
278[[[8,[9,7,8],8]]]
279
280[[1,10,1],[[5,10,2,[9,8,1],[10,6]],[8,[8,3,5,0,6],[10,2,6,0,7],2,5],[[],10,3,5,10],[[0,5,4],1],[[4,2,0,2],4,[10],6]],[4]]
281[[2,6,[5],10],[],[0,5,1,[]]]
282
283[[[[10,9,0,2,10],[]],[2],5,[7,[1,3,2],[0,0,8]]],[],[[[4,7,8,4],[8,9,0],7],0,[[1,5,4],[],[2,3,2,5,9],8,7],4,[8,9,[0,4,7,10],[2,3,4]]]]
284[[2,6,[2,[7,5],4],6,3]]
285
286[[[[]],6,1,[[]],5]]
287[[[[9],4],4,[[8],5,[10,2,4,10,8],[9,4,8,5]],8],[],[[6,7,[],[7,10,10,0,3]],5,[4],3],[[],4]]
288
289[[[[9,0],[]],4,9,[],[2,3]],[2,2]]
290[[8,9,[6,[7],6,6]],[1,9,7,1]]
291
292[[[[10,8,9,4,2],[5],[4,1,5]],3,4,[[10,8,10,6,2]]],[],[2],[10,8,[],[[],[],5],[9]]]
293[[],[[[4,2,9,6]],[[9,2,4],0,0],[[],10,5],[2,[0],10],[[2,7,1,1],[8,2,8,0,3],[2,0]]],[]]
294
295[[1,[5,0,[2,10,2,10,4]],[0,[4,4,7],1,[8,8,0],0],4]]
296[[7],[[[2],1,0],10,[],[[],4,[1,5,10,8],[10,9,3]],[[0,4,10,1,9],7,2,[0,9],0]],[5]]
297
298[[[[1,1,3,5,7],8,[7,0,6,7],[],[0,2]]],[[6,[6,7,0,10],[],[]],[8],[7,9,10,2]],[]]
299[[[[9,10,6,7,0],3,[5,9]],9,[1,[5,5,10,0,5]],[[],1,5,[0,3,8],[6,2]],[10]],[[0,0,6,5,3],[10],3,9,3],[1],[[],[1]]]
300
301[[4],[[1,[5,0],1,10,5],[],2,8]]
302[[[[],6,[1,9,9],[2]],7,[9,[10]],[[],[6,6,8,5,9],1,[],[4,2,8,5,2]],[[],[5,7,4],4]],[[],[],[2],10,[]]]
303
304[[[9,9,[],9,[6,10,7,7]],[[0,3],3,[],[3,10,9,4,1]],[9,2,10,4,7],[[2],2,2,10,[6,9,4,9,3]],[0,[0,2,2,1],[8,7,9,9],4,1]]]
305[[[[],10,0,[10,3,5,7,8]]],[3,1,7,[0,3,2,8]]]
306
307[[],[2,[]],[[],8,[5,[4,9]],7],[5,[[],7,[9,3,3,9],1,[]],[[],[5,0,2]],7],[[[6,3,4,1,7],2]]]
308[[[9,[],8],[[10,2,9],[]],6],[7,[[],[4,1],[6,10,2]],1,[[8],5,6,8]],[10,1]]
309
310[[2,[[],[9,3,8,1,0],[10,6,7,4,5],10,4],[4,[3,2,7,6,1],0,[7,7,10]],[5,[10,8],[5,0,6,10]],[[5,0,4,9,4]]],[[]],[5,0,0,[]]]
311[[[],4,[3],0],[[3,[1,4,7,6],4,[],6]],[5,[[6],[1,7,6,4,5],8,7,7],4,[3,5,1,1,6]]]
312
313[[],[[[3,2,10],[0,6],1],0,[[7],3,[]]],[],[[],[9,5,[2,1,6,3,0],10]],[[[0,8,5,1],[7],4,10,[1,7]],6]]
314[[10,6,[6,[9,3,1],[]],[1,5],[1,1]],[[[8,7,0,1,5],[5],[]],[[],[0],[8,10,9,5,3],[8,8,0,10],[]],[4,[1,7,3,5,7],[2,7,0,2],[2]]],[[[10,0],10]]]
315
316[[5],[],[[],[4,[0]]],[10],[]]
317[[],[8,[[3,9,5,3],[],[9,2,7,4,0]],1]]
318
319[[],[[[0,6,9,2,10],[5,0],[0],[10,1,1,4,5]],[[8,8],[8,2,8,8],3,[6,0,7]],2]]
320[[[],6],[],[[[9,0,0]]],[[0,5,3],8]]
321
322[[10],[[[9,6,9],[0],2,5]],[1],[[[7,0],[],5,3,4],0,[[1,6],[4,3,8,6,0],6,2],3,[[],[6]]]]
323[[[9,7,3],[9,[8],9,5]]]
324
325[[[3,[2,2,8,8,7],[8,0,10,4],[1,8,1,10],0]],[[[7,8,3,8,9],4,4,[7,3,6]],[],[],[[7,8,10,5,3],1]],[[],5,[[5,6],2,4]],[[5,[],0,6,3],6]]
326[[[[9,9],[6],[]],10]]
327
328[[8,[],9,[3,0,3],[8,[8,2,1]]],[[[],[]]],[5,[6,[10,9,5],[1,10],[2,4,6],7],5,[1]],[[6],9,[],2,4],[]]
329[[9,8,7]]
330
331[[4,3]]
332[[[],[[9,9,1],[]]],[1,[[8,6],[2,3,3,5]],7,[0,[8,5,2,2,7]],3],[4,[[4,10,3,4,0],[2,7,9,3],[4,5,8,10],9],9]]
333
334[[[[6,7,3,9],[4,4,4,0,10],6,1],1],[[4,1,0,1,2],[[3]],8,7,[6,[0,5,9,6,1],4,[10,4,6,5,9]]],[],[[1],6,10,3,8]]
335[[1,[[],[2,10,3]],[[6,2],[]],[]]]
336
337[[2,[],[[4,4,3,7,3]]]]
338[[[[1,5,4,3],[4]],[],2,[5]],[[[5,6,0],9,[9,4]],2,[[10],10,[3,4]],2],[7,[3,9],4,[6,[2,6,1,3],[10,2,9],[6,5,2,5,7]]]]
339
340[[4,[],0],[],[[8],[[],7,4],7,[[9,3,9,5],[4],0,0],6]]
341[[[0,4]]]
342
343[[5,[8,[2,5,5,3,0],8,8],1],[7,[[3,7,5],10,5],4,[[5,5],[0,9,5],[9],10]],[6]]
344[[[9,6,1,[8,3]]],[]]
345
346[[2,0],[[[],[3,0,6]]],[[3],[[9,2,3],[9,10,9],[3,1]]],[[[9,6],[8,4,6,7,3],[4],6]],[5,[],1,10,[]]]
347[[2],[[6,2,7,[10,9,9,3,1],10]],[0,[8,9],[2,3,[3]],6]]
348
349[[[0,[],3,[2,0,7,9]],6],[[[]],[2,7,7],6],[8,[[1],4,[]],[5,[7,1,4,2],10],[8,9,3,10,1]]]
350[[8],[]]
351
352[[8],[[[9,4,1,4],[9,7,3,1,4],[],[5,10,9,8,9]],0],[6,8,8],[]]
353[[1,4,[],[[6],1,[10,8]]],[7,5,9,10]]
354
355[[7,[[9,2,4],4,6],3,10,[6,[1,8,4,4,1],[4,1,10],[4,7,5,3]]]]
356[[6,6,[[7,5],7,9]],[[0],[9,[6,4,8,8,10],[10,6,8,10,9]],10],[[9,10],3],[7,[5,[4,5,3],8,[6,9,1,2]],[[8,1,6,8],[2]],5,6],[]]
357
358[[],[],[],[],[]]
359[[3,7],[],[3,[10,[5,1],[0,1]],[6,8,[0,2,8,8,0],[]],7]]
360
361[[[4,[3,10,4,3,9],9,[]],9,[10,[9,7],3]],[[[6,1,3]],7,[8,[0,0],5],[[6,3],3,4,4,5]]]
362[[[7,[1,1,8,9,4],5,[9,0],[5,6]],[],[[9,0,5,2],[4,3,9,0,4],1]],[[9,10,[6,2,1,10]]],[],[[8]],[]]
363
364[[3,5,6,8,[[7,0,3,2],[6,6,7],[6,2]]],[5,10,[2,1,7,[10],1],5],[[],[[7],[0,1,5,3]],4,[3],[[4],[4]]]]
365[[2],[0,1,[]],[[1,6,1,[5,10,3],[2]],[1],[6],[],[[2,6,6],8,[3,10,6,10,4],2,[]]],[],[[[],[8,8,6,1],[7,2,0,6],3],[6,[0,0,7,1,10],[3,3,10,0,4],[2,3,8],10]]]
366
367[[8,[]]]
368[[],[2,[2,[0,1,2,5],[10,5]],[],10],[[7,8,8,[3,8,5,2,3],8],0,[],7]]
369
370[[[[]],0,8,7,5],[3]]
371[[0]]
372
373[[],[0,7,8]]
374[[[7],[4,[1]]],[7,[[6,4,0,3]],4],[6,[],[[3],2,9,[10,7,6,3,7]]],[[[8,4],5,8],9,10,[[4,2],7,[6,10]]]]
375
376[[[],0,[[],1]],[[[9,9,3,4],[5],[10,10,9],10,2],[[7,6,10],1,[],[5,5,4]],0,5]]
377[[0,3]]
378
379[[10,10,[[9,2],[3,1],[9,10,0,2]],[7,[1,5,3,4,6]]],[3,[[7,8,5],[4,0,0,0]],1,[[2,2,0,8,7],[1],[9,6,9,5],4]],[],[[8,6,2,5,[9,10]]]]
380[[[5,[8,9,3],[0,3],10],7],[[],[5,3,[8],9,7],[0,6,6]],[[2,9,[6,9,4,4],6,[4,3]]]]
381
382[[9,[1,[5],[],5],[[4],6,0,0,10],6]]
383[[[3,[1,5,10,1],[7,0,9,4],2,4],[0],8,[4,1,[]]],[7,[[8,9,6,9],[9,0],[5,3,9],[0,8]],2,[9,6,[2,4,1]],[[8,8,3],4,9]]]
384
385[[],[2],[1,[6,[1,8],[]],8,[[],8,1,7,[]],2],[]]
386[[[10,7,4,[2],8]],[9,1,[[6],[],[4,6,0,10,3],[10,9]]],[],[[5,[0,1,8,10,10],[4,3,7,8,0],[],[4,2]],0,[[10,0,5,0]],[],[[4,0,1,0],7]],[[],2,7]]
387
388[[3,[[6,8,9,9],[1,9,1,8],3],[]],[]]
389[[[],5,1,[]],[[9,6],[],5,[[1,3],[],[4],1]],[[[5,10,10,8,7],2,[0,7,2]],10,7],[[[0],0,9,8],1,7,[]],[2,[[9,7,0,1],3,8,[]],[9,8,[]],9]]
390
391[[10,[[4,8,1,7],[9,8,6]],5,8],[[[],[9,7],3,[1]],[8,6,2,[3,7,5],4]],[[5],1,7,[8]]]
392[[4,[[1,2,9],[6,5,10,8,1],[0,10]]],[3,4,[[1],5],[0,5,1,[1],[0,1,0,5]],9],[[4],2,[[1,8,6,7],9,5,[3,3,7,8]],[[7,6,6],[8,10,2]]],[7,[6,[5],[],8]],[[[4,5,2,9],9,[3,9,9]],6,5,[]]]
393
394[[[[1,2],10,2],[[],[1,6],[10,4,10,7],[],[5,9]],[[],1,[]]],[[],[]]]
395[[],[[],6],[6,[[6,9,7,7,3],[1,5],[8,1,0,4],[2,6,7,6],[2,3,6]],4,[[6,0,1],[1,4,5,7,7],0,[6,3],[2,1,3,0]]]]
396
397[[[[3,2,9],[6,9,2,1],10,9]],[],[8,[2,[6,8],[],6,9],[5,5,6,[8]]],[[[8,2,2,1],6],[[1,8,2,3],10,[3],[]],7,[[],7,[2,9],3,6],10]]
398[[],[[],2,[],8,9],[],[10,[6,7,[9,6],[8,6,0,1]],[[10,1,3,3,1],9,[1,8],[9,5,8]],4,[]]]
399
400[[[[2,6,6],[7,7,8,9],[2,5],2,7],[],4]]
401[[5],[[4,8,3,6]],[10,1,10,[0,[0,6,1,4]]],[6],[7,10,10,[[],1,[],0,[10,3,6]]]]
402
403[[[],8,[7,[8,9,1],[3,4,8,6],[]]],[]]
404[[6,[],1,[[8,3,2,9,3],0,3,[],1]],[7,[[5,10,1],[0,8],0,8,6]]]
405
406[[8,8]]
407[[[[3,1,6,1,6],9,10],[[0,4,9,7,7],[2,3,7,2,10]],9,9],[[[9,3,10],0],[],[[9]]],[],[[],9]]
408
409[[[[10,3,8],[3,7,7,2],[1]]]]
410[[0,[],4],[]]
411
412[[[[8,9,3]],[[8]],8,5],[0,5,5],[[[2],[6,2,4,5,9],2,0],4,[5,[],[],[6,10,0,0,6]],[[10,6],[8,4,10],3,3],9]]
413[[[5,1,[3,4]]],[[4,[2,8,9,6],[1,8,3,8],1,[8]],2,1],[[3,[3,3,10]]]]
414
415[[9,[],[2,[9],5,9,[1,9]],[[6,6,6,6],9,8,3],[[],3,6,[1,4,0,3],[10,0,5,5,3]]],[0,[7,[9,4],[10,10]],5],[5,5,6],[]]
416[[[5,7,[9,4,10,9],8,0]]]
417
418[[5,[[6],1],7],[],[[[9,2,5]],[8,[10,8,10,9,1],2],8,[7,5]],[1,9,[8],2],[6]]
419[[[[],7],[],[2,9,[3],10],[[4,8,7,1,8],2,[7],[10,5,0,4,5],2]]]
420
421[[],[[[0,2,7,10],[2,8,2],[5,0,7,5],[10,9]],9],[[9,9,9,[9,8,4,10]]],[10,10,[9],[],[[3,10,8,1],[8],[2],[4,4,8,0]]],[[2,[6,2,10,6],10,[1,6],[]],[5,0],4]]
422[[2],[6,[6],[[4,9,4,10],7,[2,1,7,8],[3,9],5]]]
423
424[[[]],[7,[3,[4,7,5,0],1,[0,6,2]],5,[[0,2,8,7],0,[9,3],5,[7,7,0,6,1]]],[8,0,5,[[],2]],[[10,[10,6,6]],[[7,1,6,10]]],[1,[2,3,5,[5],[8,7]],[0,9,[1,5,6],9,[]]]]
425[[4,3],[[[4,9],[],[4],[5,2,2]],[1],[10,[6]],[[7,5],[9,10]],[[3,1,3,3,10],4]],[6,5],[],[[10,[9,4]],10,10,10,6]]
426
427[[10,5,[[0,5,9],0,2,8,[8]],1],[[],1],[7,5],[],[[[10,9],10,0],[[],[8,7,4,4,10]],[4,[9,8]]]]
428[[0,[4],[3,8,[10,2],[5,10]],[10,2,[1]]],[[[7,0,8],[9,5,0],[5,5,3,10],[0,10,6,1,7],[2,10]],0,[8,10],[[7,4,7,7,5],[2],5,[3,10,0,0],1]],[[0],5,[9,7]],[[8,3,[6,3],[5],[7,9]],[[5,1,2,4,9],[3,3,6,1,4]],[[],3]],[]]
429
430[[],[0,[1,7,[2,0,9,9],6],4,[4,6,4,[8,5,1,1],0]],[6],[[[7,1,8],[],[7]]]]
431[[7,[2,2,4,9],[1,[],[10,6,5,2]]],[3,[10,8,9,[]],[[5,3,6],4,[2,9,6],[1]],7],[8,[[8,7],2,[],[1,1,4,10],[3,0,1,1]],[],[[10,8,2,1,1],[7],[2,6,1,7,4],7,7],9],[2,[],[3,2,[8,9,6,5]],[5,0,6,8,[8,6,0]],1]]
432
433[[],[5,[[9,8],6],[0]],[0,3],[],[[],[6,3,0,3,9],8]]
434[[[[6,3,10,8,5],[0,6,9,4],2,7,9]]]
435
436[[3],[10,7],[],[4]]
437[[],[8],[1],[[[4,10,8,1]],8]]
438
439[[[3,[8,5]],[9,[9,10],[],[]],5,[2,[6,8],[8,5]]],[[[7]],6,0],[3,8,1],[[[7,5,9],8,8,8],7,6]]
440[[[2],[[9,5,1,1],6,[1,0,8,3]]],[6,1,6],[],[7,0,10,1],[[[8,5],[0,2,9,3]],3,10,3]]
441
442[[10],[],[6,6]]
443[[5],[[[4,7],[9],[10,8,9,10,6],2,[4,1,5,4,10]],[],[3,2,4],[6,[],[4,2,3],[]]],[[[5,4,8,0,8],9,[]],10,[]]]
444
445[[1],[7,[[],5],[0],[[],[1,8],[]]],[[7,6]]]
446[[],[],[[10],[5],[],[[1,0,9,2]]]]
447
448[[5,7,10],[],[0,5,[[1,7,5],9,[0,1],[9,5,6,5]],[[10,3,7],[8],[10]]],[1,[]]]
449[[2,[0,10],[8,5,[7,9],0,7],6],[4]]
diff --git a/day13/solution.nim b/day13/solution.nim
new file mode 100644
index 0000000..901e646
--- /dev/null
+++ b/day13/solution.nim
@@ -0,0 +1,121 @@
1import strutils
2import strformat
3import algorithm
4
5type
6 Data = ref object
7 val: int
8 list: seq[Data]
9
10 Packet = tuple
11 first: Data
12 second: Data
13
14 Input = seq[Packet]
15
16proc `$`(data: Data): string =
17 if data.val != -1:
18 return fmt"{data.val}"
19
20 result = "[" & data.list.join(",") & "]"
21
22proc parseData(strData: string, i: var int): Data =
23 result = Data(val: -1, list: newSeq[Data]())
24 let dataLen = strData.len()
25 while i < dataLen:
26 case strData[i]:
27 of '[':
28 i += 1
29 result.list.add(parseData(strData, i))
30 of ']':
31 i += 1
32 return result
33 of ',':
34 i += 1
35 else:
36 var j = i
37 while j < dataLen and strData[j].isDigit():
38 j += 1;
39 let toPush = Data(val: strData[i..<j].parseInt())
40 result.list.add(toPush)
41 i = j
42
43proc parsePacket(strPacket: string): Packet =
44 let strDatas = strPacket.splitLines()
45 assert(strDatas.len() == 2)
46 var
47 i0 = 0
48 i1 = 0
49 result = (parseData(strDatas[0][1..^2], i0), parseData(strDatas[1][1..^2], i1))
50
51proc parseFile(content: string): Input =
52 let strPackets = content.strip().split("\n\n")
53
54 for strPacket in strPackets:
55 result.add(parsePacket(strPacket))
56
57proc compare(A, B: int): int =
58 if A < B: return -1
59 elif A > B: return 1
60 else: return 0
61
62proc dataListForm(data: Data): Data =
63 # Check if its already in list form
64 if data.val == -1:
65 return data
66 result = Data(val: -1, list: @[data])
67
68proc compare(A, B: Data): int =
69 # Both numbers:
70 if A.val != -1 and B.val != -1:
71 return compare(A.val, B.val)
72
73 # Transform both data to list form
74 let
75 A = dataListForm(A)
76 B = dataListForm(B)
77
78 assert(A.val == -1 and B.val == -1)
79 # Both are lists now
80 let
81 li = A.list.len()
82 lj = B.list.len()
83 N = min(li, lj)
84
85 var i = 0
86 while i < N:
87 let res = compare(A.list[i], B.list[i])
88 if res != 0:
89 return res
90 i += 1
91
92 return compare(li, lj)
93
94proc part1(Packets: Input): int =
95 for i, packet in Packets:
96 # echo fmt"Checking packet {packet}"
97 let comparison = compare(packet.first, packet.second)
98 # echo fmt"result = {comparison}"
99 if comparison < 0:
100 result += i+1
101
102proc part2(Packets: Input): int =
103 let driverPackets = parseFile("[[6]]\n[[2]]\n")
104 let first = driverPackets[0].first
105 let second = driverPackets[0].second
106 var datas = @[first, second]
107
108 for packet in Packets:
109 datas.add(packet.first)
110 datas.add(packet.second)
111
112 datas.sort(compare)
113 let firstIndex = datas.binarySearch(first, compare) + 1
114 let secondIndex = datas.binarySearch(second, compare) + 1
115 return firstIndex * secondIndex
116
117let content = readFile("./input.txt")
118let input = parseFile(content)
119
120echo part1(input)
121echo part2(input)