summaryrefslogtreecommitdiffstats
path: root/2020/day3
diff options
context:
space:
mode:
authorYigit Sever2021-12-13 10:38:11 +0300
committerYigit Sever2021-12-13 10:38:11 +0300
commit74b27ccca31bb757c737dd7fdc02f513f57561b2 (patch)
treee27db4cd0873c81a53d32277446d926d176304e0 /2020/day3
parent3919f90cfbfbba26c8e39f979280649f5e08aea8 (diff)
parentac8125750abed263619da4cc6d653bb5ab76f007 (diff)
downloadaoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.gz
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.tar.bz2
aoc-74b27ccca31bb757c737dd7fdc02f513f57561b2.zip
Merge remote-tracking branch 'origin/main'
Diffstat (limited to '2020/day3')
-rw-r--r--2020/day3/README.md11
-rw-r--r--2020/day3/input323
-rw-r--r--2020/day3/toboggan.pl30
-rw-r--r--2020/day3/toboggans.pl40
4 files changed, 404 insertions, 0 deletions
diff --git a/2020/day3/README.md b/2020/day3/README.md
new file mode 100644
index 0000000..75737af
--- /dev/null
+++ b/2020/day3/README.md
@@ -0,0 +1,11 @@
1# day 3
2
3## first part
4
532 places per row, right 3 and down 1 is
6
7```
8idx = (idx + 3) % 32
9```
10
11per line but this will _probably_ change for the part 2.
diff --git a/2020/day3/input b/2020/day3/input
new file mode 100644
index 0000000..831458f
--- /dev/null
+++ b/2020/day3/input
@@ -0,0 +1,323 @@
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........#...................##.
69....#.......#.....#.......#....
70....##.........#.#.............
71......#..#........#.#...#......
72.#..#...#...........#......#..#
73.#....#.#........#............#
74......#...................#...#
75##...#.......................#.
76........###.......#.......#..#.
77...........##.............#....
78..##...#.....#....#......#....#
79................###...##...#.#.
80..#.#.....#....##...#..##......
81.....................#.#......#
82.......#....##.#..#........##..
83.##....#......#....#.........#.
84#............#.........#..#.#..
85....#...........#..#....#....##
86.......#..#.....##.........#...
87.##..........#.#.#....#..#.....
88........#....##.##.#......#....
89....##..##......##.....#.###...
90......##.#....##.#.#....#......
91..#..#..........#.....##.....##
92#........#.##...#.#....#....###
93........##............#........
94##.##..##.#..#...##............
95....#..#....#...........#....#.
96..#.......#.#.......#...#......
97.#..........##.....#..#...#...#
98.................##.#...#...##.
99##.............#......#....#...
100..........#.#....#.............
101...##..#.#.....#.....#.#.......
102...##...##.#......#.#...#......
103..#..#.....##..##..........##..
104......##........##.......#....#
105....#..####..#...##........#...
106#.......#....#.......##.......#
107........#..........#.........#.
108.....#....#.........#.#.#.....#
109..##.....#....#....#..#......#.
110....#..#.##...#..#.....#......#
111........###.........#..###...#.
112.....#.......#.....#.#.#.......
113...##.....#....##.....#.#.#...#
114#.##....#.##.....#.#.#........#
115.##..#.......#...#.#.......#...
116.#..........#.............#....
117.#...#...#......#..##..........
118.......................#.#....#
119............###....#..##.#..#..
120...#.#......##....#..#.........
121..#...#....#....#.#............
122..#.#..###...............##....
123.....##...#.....#........#..#.#
124...........#......#..#...#.##.#
125#...##......##...#..#...#..#...
126..##....#............#......#.#
127.#.#..#...#...#.#...#...##..##.
128..#.#....#.......#.#.#.#.#.##..
129....###.##..#...##....#........
130.#...............#........#....
131...#..#........##...#.##.......
132........#..#..#......##........
133##....#....#............#......
134#....#...#.###.#.###.......#...
135...#.###.##....#.........#...##
136..#......##.#.....#..#.......#.
137##.............#..#..##....#.#.
138#...#...##........#.#.......#..
139........#..#.....#.#..#..#.#...
140#..##.........#.#.#.##...#....#
141............#...#....#..#....#.
142.....#.......#......##..#......
143.#.....................#......#
144...................#....#.#....
145.....#....#.....##.............
146#....##.#....##..#....##....#..
147....#..........#..........#....
148.....#.#...............#..##...
149...#......###.......#..##......
150#.#.#....##..#......#.##.#.....
151.#...###..#.....##.........#.#.
152..#...#.............#....#.....
153#..#.............#.....#.....#.
154.#.........#.#...#..#....#...#.
155#....#......#....#.#..........#
156.........................#.....
157...................#...........
158#.#...#......#....#............
159.#..#........#...##....#....#..
160..#......#..#..........##......
161#.#....#....##....#.........#..
162...#.#.#.#..#....##..#....#..#.
163..#..............#.....##......
164....#.........#...#.....#..#...
165..#..................#.#.......
166.....##.##........#.#....#..###
167..#.#...#.....#..##..##.#.#.#..
168.....#......#............#.....
169.#.......#....##...............
170...#.................#.....#...
171...#.#..#.#...##........#....##
172..........##...................
173#........#..........#.#........
174................#..##.##.#....#
175....##..#.#.#...#...#....#.#.#.
176..#.........#......##....#.....
177.##.........#.....#.#..........
178...##...###...........#......##
179..#........#......#.....##.#...
180###.....#.#.#...#.......#....#.
181..##...#....###..##.#.#..##....
182..###...##.......#.#..#....#..#
183..#...............###....#..#..
184...........#....#.##..#........
185.#...#..#.#...##..#....#...#..#
186..#............#......#.....#..
187.#...#...#.#...#.#.............
188...####.........#....##....#.#.
189.....##...#........#.#......#..
190...####...#.#..#.#.#.#.........
191........#.##.#..#.......#......
192......##......#.........#.#....
193..#.#...#....#.....###.....##..
194#.#.##..........#...##..#..#.#.
195.....#................#.#..#..#
196.........#........#.....#..#..#
197......#...........#...........#
198..#........#.#.........#...##..
199.....####.....#....##.#........
200....#...#........#.......#...#.
201...#..#....#.....##....###.....
202........#..#..#.#.#............
203#..#......#..#....#....#.#.#..#
204.........#...#......##.........
205..#....#............#..#.....#.
206#............#.#...#......#...#
207..#..##...#........#.........##
208.#...#....##...#.......#..##...
209#..#.##......#........##...#...
210...#..........#...#..#..#....#.
211##..#........##..##...#..###.#.
212............##...............#.
213#......#...#....#.........#...#
214................#..#.#.........
215.....#...#...#...##.......#...#
216..##.###...#...#.#..##.#.#...#.
217#...##..........#....##.#.#.#..
218.#.........#..........#........
219.......#.#...............#.....
220...#...#............#..........
221.........#..#..........#.......
222.........#..#...#....#.##....#.
223..#............#......#....#.##
224...#...#.#........#......#..#.#
225........#......##...##...#..#.#
226.......###......#............#.
227#.....#...##.#.#...#.......#.#.
228..#......#..............##....#
229..#............##.......#.#.#.#
230...#.#.....#.#.#........####...
231...#................#..........
232..#...#....#....#......#..#...#
233.###......#..............#.#..#
234......#......#..........##..#..
235...##.#...........#.#.....##.#.
236.#...#......#..........#.......
237....#...#....#..........#.#....
238..................##..#.....#.#
239###.................#......##..
240.....#.....#............#.#..#.
241.....#........#...#....#.#.....
242#.#...#........................
243.#...#.......#..#.......#......
244.......#.#.....###.#...#.#.....
245#...#.#...........##...#.......
246.#.......#.....#..#..#....#....
247...#..##.....#..#..#.....#.....
248...#................###......#.
249#..#...##.###..#..##.......#...
250.#.#.#........#.#.............#
251#.......#..#.......#.....##...#
252.#.#.#............#..#....#.#..
253...#.#.##.#......##.....#....##
254#............###...#....#......
255.....#..#..#.#.........##.#....
256.#.##........#.#.#...#.......#.
257..###..#..#.#...#.##...###.....
258#............#.............#...
259.#.##.....#..#.......#...#...#.
260.#...#........###...####.......
261.#.#..##..#.....#.#..#.........
262....#.#.#............##..#...#.
263###.##......#.#.....#.....#....
264.........#...##.....##....#....
265..#................#.........#.
266#.......###..##..##............
267.....#...#.............#..#..#.
268..........#...................#
269....#....#...........#.........
270.##.......##.##.........##.....
271#......#.#....#....#...#.#.#...
272..#.##..#.###.#.##....#..#.....
273#....##.#...#..................
274.......#...#...........#...#...
275....###.#...#..#...............
276##.#.#..#.#......#.#......#...#
277.............#.....#.##....#...
278#.............###....#...#.##.#
279#..#.##.............#.##...#...
280.#.#......#.........#...#......
281.#.........#.#.#.....##.#.#....
282.................#........#....
283....##.#.#..#.........#........
284#...##......##....#.#..#......#
285..........##...##..#......##...
286..........#..#.#..##..#..#.....
287..#..#.....##........#...#.#...
288#..........#.#.#..............#
289#..........##.....#.#...##....#
290.....#...#..#..#...##.#.......#
291.##.#...............#.#...#....
292..........#.....#......#.......
293.....#.#......##...#.......#...
294...........#.#...#.....#....#.#
295.###.#........##....#.##...#...
296#....#.##....#.###..##.#.......
297##...........#..##.........#...
298....#.##...#...#.....#.#..#....
299........#.#.#..#.#...........##
300..........#.##...#....#......#.
301.##.....#.#.....##.#.......#.#.
302.#..#....#.#.....#.##.#....#..#
303#.......#..#..........##....#..
304.#........#...#..#.#...#....#..
305#......##...#...##..#.#.......#
306.#......#.##.#............##.#.
307.#....#.....##..##..........#..
308..###..#..#...#...#.#.#..##....
309.#.#.##...#..#...........#....#
310....#......#.......##...#.#.#..
311.......#..#...##..#.........#..
312....#..#.#.......##........#..#
313........#.#....#.##..#.......#.
314.....#.......#.#...#.#.........
315........#...#....#.#....###..#.
316......#..#.##..##..#...#.#.....
317.#.#.....#.....#....#...#...#..
318...#..#...#..#......#..#.#.....
319...##...#...........#..#......#
320..#...#####..#.#.##....##......
321...........#......#.#..#.......
322..#....##..#.##.......#.#.#..#.
323..#..#........#...#.......#....
diff --git a/2020/day3/toboggan.pl b/2020/day3/toboggan.pl
new file mode 100644
index 0000000..d424a83
--- /dev/null
+++ b/2020/day3/toboggan.pl
@@ -0,0 +1,30 @@
1use strict;
2use warnings;
3# use Smart::Comments;
4
5open my $fh, '<', "input" or die "no input present, $!";
6
7my $right_m = 3;
8my $toboggan = 0;
9
10my $trees = 0;
11
12while (my $line = <$fh>) {
13 chomp $line;
14
15 ### $line
16 my $curr = substr($line, $toboggan, 1);
17 ### $curr
18
19 if ($curr eq "#") {
20 $trees++;
21 }
22
23 ### $toboggan
24
25 $toboggan = ($toboggan + $right_m) % 31;
26
27}
28
29print($trees);
30
diff --git a/2020/day3/toboggans.pl b/2020/day3/toboggans.pl
new file mode 100644
index 0000000..ebf7ae4
--- /dev/null
+++ b/2020/day3/toboggans.pl
@@ -0,0 +1,40 @@
1use strict;
2use warnings;
3# use Smart::Comments;
4use DDP;
5
6open my $fh, '<', "input" or die "no input present, $!";
7chomp(my @forest = <$fh>);
8close $fh;
9my $len = scalar @forest;
10
11my @right_ms = qw/1 3 5 7 1/;
12my @down_ms = qw/ 1 1 1 1 2/;
13my $runs = $#right_ms;
14
15my $all_trees = 1;
16
17foreach my $run (0..$runs) {
18
19 my $toboggan = 0;
20 my $trees = 0;
21 my $down_mov = $down_ms[$run];
22 my $right_mov = $right_ms[$run];
23
24 for (my $line = 0; $line < $len; $line += $down_mov) {
25 my $curr = substr($forest[$line], $toboggan, 1);
26 if ($curr eq "#") {
27 $trees++;
28 }
29 $toboggan = ($toboggan + $right_mov) % 31;
30 }
31 $trees ||= 1;
32 $all_trees *= $trees;
33 ### this run is
34 ### $right_mov
35 ### $down_mov
36 ### got: $trees
37 ### so far: $all_trees
38}
39
40print("$all_trees");