diff options
Diffstat (limited to '2020/day3/toboggan.pl')
-rw-r--r-- | 2020/day3/toboggan.pl | 30 |
1 files changed, 30 insertions, 0 deletions
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 @@ | |||
1 | use strict; | ||
2 | use warnings; | ||
3 | # use Smart::Comments; | ||
4 | |||
5 | open my $fh, '<', "input" or die "no input present, $!"; | ||
6 | |||
7 | my $right_m = 3; | ||
8 | my $toboggan = 0; | ||
9 | |||
10 | my $trees = 0; | ||
11 | |||
12 | while (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 | |||
29 | print($trees); | ||
30 | |||