diff options
author | Yigit Sever | 2021-12-12 01:24:32 +0300 |
---|---|---|
committer | Yigit Sever | 2021-12-12 01:24:32 +0300 |
commit | 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e (patch) | |
tree | d6478c85c0488a1059567ccd2882cb10039c2546 /2020/day3/toboggans.pl | |
parent | ae3853b6e8ab02023ccd74baac6dc177b1ee879a (diff) | |
download | aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.gz aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.tar.bz2 aoc-4bb6f8d06c0e384f3394012b1d48da58ed28cc5e.zip |
2020, tracking
Diffstat (limited to '2020/day3/toboggans.pl')
-rw-r--r-- | 2020/day3/toboggans.pl | 40 |
1 files changed, 40 insertions, 0 deletions
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 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | # use Smart::Comments; | ||
4 | use DDP; | ||
5 | |||
6 | open my $fh, '<', "input" or die "no input present, $!"; | ||
7 | chomp(my @forest = <$fh>); | ||
8 | close $fh; | ||
9 | my $len = scalar @forest; | ||
10 | |||
11 | my @right_ms = qw/1 3 5 7 1/; | ||
12 | my @down_ms = qw/ 1 1 1 1 2/; | ||
13 | my $runs = $#right_ms; | ||
14 | |||
15 | my $all_trees = 1; | ||
16 | |||
17 | foreach 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 | |||
40 | print("$all_trees"); | ||