From 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 12 Dec 2021 01:24:32 +0300 Subject: 2020, tracking --- 2020/day3/README.md | 11 ++ 2020/day3/input | 323 +++++++++++++++++++++++++++++++++++++++++++++++++ 2020/day3/toboggan.pl | 30 +++++ 2020/day3/toboggans.pl | 40 ++++++ 4 files changed, 404 insertions(+) create mode 100644 2020/day3/README.md create mode 100644 2020/day3/input create mode 100644 2020/day3/toboggan.pl create mode 100644 2020/day3/toboggans.pl (limited to '2020/day3') 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 @@ +# day 3 + +## first part + +32 places per row, right 3 and down 1 is + +``` +idx = (idx + 3) % 32 +``` + +per 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 @@ +.....#.........#...#..##....#.. +.#........#...#........#....... +......#......#..#...#....#.#..# +...#.#####.#.......##.#........ +...........#......#..#.....#... +#.#..#...#.#...#.##.....#.....# +....#..#....#...#.#...#.##..... +##...#..........##..######..... +.....#...#......#.............# +........##....#...##..#....#... +...#...#.........#.#..........# +..#.#.....##..........#........ +##.......................#..... +#..#...##...##.#.........##.... +.#....#.#####....#...#...#..... +#......#......###..#........#.# +.#....##..##.###.#.......#..... +.#..#.........##....#.#....#... +........#..................#... +.......#..#..#............#.... +........#...................##. +.#......#......#.####......#... +..###.#..#..#.........#........ +..#...........###..#.....#.##.. +...#.##.#....#................# +#.....#.............#.#........ +.#..............#.........#.... +##.................#..........# +.#..#....#.###....##..#..#...#. +##........#......##.....#....## +#......#..#........#......#.#.. +....#.##.#.............#...##.. +.#...#...#..#............##...# +.#..#...#..#..#....##..#.#.#... +#....#...##.#.#......#........# +#..#..#...#.#.....#..##.#...... +.....#..#.#..#.##.......#..###. +#......#......#...#............ +.....#......#......#..#.##..#.# +......#..##..#.....#....#...... +..#..#...#..#...#....###.#.#... +.................#..#.......... +......#...##..#.....#...##..... +..#...............#...#.#.....# +.#....#.##.##..#.........##.... +...###....##...#......#......## +....#...#.....#.........#..##.. +..###.........#..#..#...#...... +...##.....#.........#.......#.. +.....#.................#.#..... +.#.###.#..#...#..##....#....##. +....#.....##.........#.#....... +.#.#....#..#................#.. +..#.#......#......#........#... +#........#....#..#..#..#....#.# +#...........##..#....#..####... +.....#.......#.#...#.#....###.. +.......#....#.......#.......... +.............#.....#........... +#....#......#...#..##.#........ +....#.......#.#.......#....###. +.####.#...........#.#.#...#.#.. +#..##....##.#......#........... +...##...#.#.....#.....#........ +...#.............#.....#...#... +...#.....#..#.....##...###..#.# +....##..#..##..#..#...#.....#.. +........#...................##. +....#.......#.....#.......#.... +....##.........#.#............. +......#..#........#.#...#...... +.#..#...#...........#......#..# +.#....#.#........#............# +......#...................#...# +##...#.......................#. +........###.......#.......#..#. +...........##.............#.... +..##...#.....#....#......#....# +................###...##...#.#. +..#.#.....#....##...#..##...... +.....................#.#......# +.......#....##.#..#........##.. +.##....#......#....#.........#. +#............#.........#..#.#.. +....#...........#..#....#....## +.......#..#.....##.........#... +.##..........#.#.#....#..#..... +........#....##.##.#......#.... +....##..##......##.....#.###... +......##.#....##.#.#....#...... +..#..#..........#.....##.....## +#........#.##...#.#....#....### +........##............#........ +##.##..##.#..#...##............ +....#..#....#...........#....#. +..#.......#.#.......#...#...... +.#..........##.....#..#...#...# +.................##.#...#...##. +##.............#......#....#... +..........#.#....#............. +...##..#.#.....#.....#.#....... +...##...##.#......#.#...#...... +..#..#.....##..##..........##.. +......##........##.......#....# +....#..####..#...##........#... +#.......#....#.......##.......# +........#..........#.........#. +.....#....#.........#.#.#.....# +..##.....#....#....#..#......#. +....#..#.##...#..#.....#......# +........###.........#..###...#. +.....#.......#.....#.#.#....... +...##.....#....##.....#.#.#...# +#.##....#.##.....#.#.#........# +.##..#.......#...#.#.......#... +.#..........#.............#.... +.#...#...#......#..##.......... +.......................#.#....# +............###....#..##.#..#.. +...#.#......##....#..#......... +..#...#....#....#.#............ +..#.#..###...............##.... +.....##...#.....#........#..#.# +...........#......#..#...#.##.# +#...##......##...#..#...#..#... +..##....#............#......#.# +.#.#..#...#...#.#...#...##..##. +..#.#....#.......#.#.#.#.#.##.. +....###.##..#...##....#........ +.#...............#........#.... +...#..#........##...#.##....... +........#..#..#......##........ +##....#....#............#...... +#....#...#.###.#.###.......#... +...#.###.##....#.........#...## +..#......##.#.....#..#.......#. +##.............#..#..##....#.#. +#...#...##........#.#.......#.. +........#..#.....#.#..#..#.#... +#..##.........#.#.#.##...#....# +............#...#....#..#....#. +.....#.......#......##..#...... +.#.....................#......# +...................#....#.#.... +.....#....#.....##............. +#....##.#....##..#....##....#.. +....#..........#..........#.... +.....#.#...............#..##... +...#......###.......#..##...... +#.#.#....##..#......#.##.#..... +.#...###..#.....##.........#.#. +..#...#.............#....#..... +#..#.............#.....#.....#. +.#.........#.#...#..#....#...#. +#....#......#....#.#..........# +.........................#..... +...................#........... +#.#...#......#....#............ +.#..#........#...##....#....#.. +..#......#..#..........##...... +#.#....#....##....#.........#.. +...#.#.#.#..#....##..#....#..#. +..#..............#.....##...... +....#.........#...#.....#..#... +..#..................#.#....... +.....##.##........#.#....#..### +..#.#...#.....#..##..##.#.#.#.. +.....#......#............#..... +.#.......#....##............... +...#.................#.....#... +...#.#..#.#...##........#....## +..........##................... +#........#..........#.#........ +................#..##.##.#....# +....##..#.#.#...#...#....#.#.#. +..#.........#......##....#..... +.##.........#.....#.#.......... +...##...###...........#......## +..#........#......#.....##.#... +###.....#.#.#...#.......#....#. +..##...#....###..##.#.#..##.... +..###...##.......#.#..#....#..# +..#...............###....#..#.. +...........#....#.##..#........ +.#...#..#.#...##..#....#...#..# +..#............#......#.....#.. +.#...#...#.#...#.#............. +...####.........#....##....#.#. +.....##...#........#.#......#.. +...####...#.#..#.#.#.#......... +........#.##.#..#.......#...... +......##......#.........#.#.... +..#.#...#....#.....###.....##.. +#.#.##..........#...##..#..#.#. +.....#................#.#..#..# +.........#........#.....#..#..# +......#...........#...........# +..#........#.#.........#...##.. +.....####.....#....##.#........ +....#...#........#.......#...#. +...#..#....#.....##....###..... +........#..#..#.#.#............ +#..#......#..#....#....#.#.#..# +.........#...#......##......... +..#....#............#..#.....#. +#............#.#...#......#...# +..#..##...#........#.........## +.#...#....##...#.......#..##... +#..#.##......#........##...#... +...#..........#...#..#..#....#. +##..#........##..##...#..###.#. +............##...............#. +#......#...#....#.........#...# +................#..#.#......... +.....#...#...#...##.......#...# +..##.###...#...#.#..##.#.#...#. +#...##..........#....##.#.#.#.. +.#.........#..........#........ +.......#.#...............#..... +...#...#............#.......... +.........#..#..........#....... +.........#..#...#....#.##....#. +..#............#......#....#.## +...#...#.#........#......#..#.# +........#......##...##...#..#.# +.......###......#............#. +#.....#...##.#.#...#.......#.#. +..#......#..............##....# +..#............##.......#.#.#.# +...#.#.....#.#.#........####... +...#................#.......... +..#...#....#....#......#..#...# +.###......#..............#.#..# +......#......#..........##..#.. +...##.#...........#.#.....##.#. +.#...#......#..........#....... +....#...#....#..........#.#.... +..................##..#.....#.# +###.................#......##.. +.....#.....#............#.#..#. +.....#........#...#....#.#..... +#.#...#........................ +.#...#.......#..#.......#...... +.......#.#.....###.#...#.#..... +#...#.#...........##...#....... +.#.......#.....#..#..#....#.... +...#..##.....#..#..#.....#..... +...#................###......#. +#..#...##.###..#..##.......#... +.#.#.#........#.#.............# +#.......#..#.......#.....##...# +.#.#.#............#..#....#.#.. +...#.#.##.#......##.....#....## +#............###...#....#...... +.....#..#..#.#.........##.#.... +.#.##........#.#.#...#.......#. +..###..#..#.#...#.##...###..... +#............#.............#... +.#.##.....#..#.......#...#...#. +.#...#........###...####....... +.#.#..##..#.....#.#..#......... +....#.#.#............##..#...#. +###.##......#.#.....#.....#.... +.........#...##.....##....#.... +..#................#.........#. +#.......###..##..##............ +.....#...#.............#..#..#. +..........#...................# +....#....#...........#......... +.##.......##.##.........##..... +#......#.#....#....#...#.#.#... +..#.##..#.###.#.##....#..#..... +#....##.#...#.................. +.......#...#...........#...#... +....###.#...#..#............... +##.#.#..#.#......#.#......#...# +.............#.....#.##....#... +#.............###....#...#.##.# +#..#.##.............#.##...#... +.#.#......#.........#...#...... +.#.........#.#.#.....##.#.#.... +.................#........#.... +....##.#.#..#.........#........ +#...##......##....#.#..#......# +..........##...##..#......##... +..........#..#.#..##..#..#..... +..#..#.....##........#...#.#... +#..........#.#.#..............# +#..........##.....#.#...##....# +.....#...#..#..#...##.#.......# +.##.#...............#.#...#.... +..........#.....#......#....... +.....#.#......##...#.......#... +...........#.#...#.....#....#.# +.###.#........##....#.##...#... +#....#.##....#.###..##.#....... +##...........#..##.........#... +....#.##...#...#.....#.#..#.... +........#.#.#..#.#...........## +..........#.##...#....#......#. +.##.....#.#.....##.#.......#.#. +.#..#....#.#.....#.##.#....#..# +#.......#..#..........##....#.. +.#........#...#..#.#...#....#.. +#......##...#...##..#.#.......# +.#......#.##.#............##.#. +.#....#.....##..##..........#.. +..###..#..#...#...#.#.#..##.... +.#.#.##...#..#...........#....# +....#......#.......##...#.#.#.. +.......#..#...##..#.........#.. +....#..#.#.......##........#..# +........#.#....#.##..#.......#. +.....#.......#.#...#.#......... +........#...#....#.#....###..#. +......#..#.##..##..#...#.#..... +.#.#.....#.....#....#...#...#.. +...#..#...#..#......#..#.#..... +...##...#...........#..#......# +..#...#####..#.#.##....##...... +...........#......#.#..#....... +..#....##..#.##.......#.#.#..#. +..#..#........#...#.......#.... 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 @@ +use strict; +use warnings; +# use Smart::Comments; + +open my $fh, '<', "input" or die "no input present, $!"; + +my $right_m = 3; +my $toboggan = 0; + +my $trees = 0; + +while (my $line = <$fh>) { + chomp $line; + + ### $line + my $curr = substr($line, $toboggan, 1); + ### $curr + + if ($curr eq "#") { + $trees++; + } + + ### $toboggan + + $toboggan = ($toboggan + $right_m) % 31; + +} + +print($trees); + 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 @@ +use strict; +use warnings; +# use Smart::Comments; +use DDP; + +open my $fh, '<', "input" or die "no input present, $!"; +chomp(my @forest = <$fh>); +close $fh; +my $len = scalar @forest; + +my @right_ms = qw/1 3 5 7 1/; +my @down_ms = qw/ 1 1 1 1 2/; +my $runs = $#right_ms; + +my $all_trees = 1; + +foreach my $run (0..$runs) { + + my $toboggan = 0; + my $trees = 0; + my $down_mov = $down_ms[$run]; + my $right_mov = $right_ms[$run]; + + for (my $line = 0; $line < $len; $line += $down_mov) { + my $curr = substr($forest[$line], $toboggan, 1); + if ($curr eq "#") { + $trees++; + } + $toboggan = ($toboggan + $right_mov) % 31; + } + $trees ||= 1; + $all_trees *= $trees; + ### this run is + ### $right_mov + ### $down_mov + ### got: $trees + ### so far: $all_trees +} + +print("$all_trees"); -- cgit v1.2.3-70-g09d2