diff options
author | Matias Linares <matiaslina@gmail.com> | 2020-12-06 17:17:08 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@gmail.com> | 2020-12-06 17:17:08 -0300 |
commit | 8c6b7ffc7e0e27ddfa1c6ee51a69dbfbd752d8dd (patch) | |
tree | 43c7a67614086f9335108be6d2a7adf30a189232 | |
parent | a0fcb600572ea0da9dee1b5b9e7a24ce674ebe7e (diff) | |
download | advent-of-code-8c6b7ffc7e0e27ddfa1c6ee51a69dbfbd752d8dd.tar.gz |
Add day3
-rw-r--r-- | 2020/day3.raku | 57 | ||||
-rw-r--r-- | 2020/day3.txt | 323 |
2 files changed, 380 insertions, 0 deletions
diff --git a/2020/day3.raku b/2020/day3.raku new file mode 100644 index 0000000..9189a4e --- /dev/null +++ b/2020/day3.raku @@ -0,0 +1,57 @@ +#!/usr/bin/env raku + +use v6; + +constant \EXAMPLE = q:to/END/; +..##....... +#...#...#.. +.#....#..#. +..#.#...#.# +.#...##..#. +..#.##..... +.#.#.#....# +.#........# +#.##...#... +#...##....# +.#..#...#.# +END + +sub solve($input, Int $step-right, Int $step-down --> Int) { + # Parse it + my @m = $input.split("\n").grep(*.chars > 0).map(*.comb.Array); + my $x = 0; + my $y = 0; + my $trees = 0; + my $width = @m[0].elems; + + while $y < @m.elems { + $trees++ if @m[$y][$x] eq '#'; + + $y += $step-down; + $x = ($x + $step-right) % $width; + } + $trees +} + +multi sub MAIN('part1', $file) { + say solve(slurp($file), 3, 1); +} + +multi sub MAIN('part2', $file) { + my $input = slurp $file; + my &f = &solve.assuming($input); + say ( + f(1, 1), + f(3, 1), + f(5, 1), + f(7, 1), + f(1, 2) + ).reduce: &[*] +} + +multi sub MAIN('test') { + use Test; + subtest 'Part 1', { + is solve(EXAMPLE, 3, 1), 7, 'Example'; + } +} diff --git a/2020/day3.txt b/2020/day3.txt new file mode 100644 index 0000000..2d49b8b --- /dev/null +++ b/2020/day3.txt @@ -0,0 +1,323 @@ +.#....#..##.#..####....#....... +......#..#....#....###......#.# +#..#.....#..............##.#.#. +#.#...#....#...#......##..#..#. +...#..#.##..#..#........###.#.# +...#.#..........#.........##... +...#.#....#.#....#..#......#... +..##.#.....#.......#.###..#..## +..#.......#.......#....##...... +....##........##.##...#.###.##. +#.......#.......##..#......#... +..##.............##.#......#... +...#.####....#.....#...##...... +.............##.#......#....... +..#...#....#......#....#....... +..#....#..#............#....... +##...#..#........##..#......#.. +##........##........#.#.......# +#.......#........#.#..#....###. +.....#..#.#..........##...#.... +..##...#......#.#...#..#...#... +##.##...#......#....#....#...#. +#.......#..#.#..#....#..###.#.# +#.............#.#....#..#.#.... +...#.......###.#.##.##.#...#..# +.##.......##..##...#..###...... +.......#.#.#.#..####..#..#..#.. +...##......#.#.##.###....#.###. +###......###......#.#####..#... +..#........##..#..##.##..#...#. +.....##..#...#..#.##.....#.#... +#......#.##....#..##.#....#.#.. +##.#.##..#................#.... +......#.#....#......##.....#... +..#...##..#..#...#..#.#..#..... +........#.#.#.##...#.#.....#.#. +#.#......#.....##..#...#....... +..#.#......#...........###..... +......##....#....##..#..#.#.#.# +##....#.###...#......#..#...#.. +#.#.##....###...####.......#..# +##...........#.....#........#.# +.##.#..#.....#......#.......#.. +##..##..###....#.........##.... +..#..#..#.##...#.#...#........# +#.##.###...#.......#........... +.........#.................#... +#.##...#.....#..##........#.... +....#.#...##...#...........#... +.#.....#.#..#...##..##.....#... +.#.....####....#..##..#........ +...#..#......##.#..##.#.#.#..#. +.##.#.....#.....#...#.......##. +......#..#..#......#...####.... +.......#......##..#..##.....#.. +......#.#..#...#..#.#.......... +....##.........#............... +.#....#..##.....#....##.##..... +#.#.....#...#....####....#.#... +#.....#....#.#...#............. +...#..#.....#....##..#..#...... +...#.#............#...........# +###.#..#.#......#.....##.....#. +####....#....###.....#..#.##### +.###..#...#.#..#......##.#.#.#. +.....#.##.#....#..##....#..#..# +...#....#...##.....#......#.#.. +....#...#....#...#....#.....#.# +.#.....#.....#.#..#......#..#.. +..#..##....##.##....#.....##... +#..##...#.##...#..#.#.#.....#.. +...#..##.#..#....#.#....######. +..........#..#.....#....#...##. +#.#####.#.###..#.....#......... +#....#......#..#.#.##.##..###.. +..#...###.#.#....##.##...##.... +.......#....#..#...##......#... +...#.#...#..#.....#..##.#...... +###..##...........#............ +..#....#.##....#.#..##...#..... +##....#...#....#.....#.#..##... +..............#.##.#..#..##.### +......#..#..#..#.#....###...##. +.#...#..#.#.#....#..........#.. +..#.#.....#..#...........#.##.. +...#.#......#......#..#..#.#... +...#....#.#.#.....#...#.##..#.. +.#.#..#...#........##.......#.. +##..........#..#...#....###.#.. +#.....###......#..#.#.#....#.#. +..###.......#.#...............# +#....#.....#.#......#..##.##... +#.##.#.#....#..#.#...#.#...#..# +#....#..#...........#.......#.. +...#.####.....#.........###.##. +......#..#.....#..........#..#. +#...#.#..####...#...#.#.##...## +.##.........#......#.#.#....... +.......##...##.##....###...##.. +...#..#....#..#.#.#.....#.#.... +#....#.#.#.......##..###..##... +......#............#.#...#..#.. +#.#.....#......#...#.......###. +...#.#................#...#.... +.....#......#.#..#...##.#.#...# +#....#.#..#..#..##..#.##..#.... +#.................#..#....#.... +..#....#.......####....###..... +.#..#.#.#...###..#...#..###.... +..#..#.#......#.###..........#. +.....#......#.......##....##.#. +.#....#........#.#.##.#........ +#.#..##..#..#.#...####....##... +...#....#.#..#...#..........#.. +.#.....#.##....#...##.......... +....##....#.....#.....#...#.### +.#...##.#.#..##..#...#.#..#..#. +..#.......#.##.....#.#........# +...#...#.....##..#.#.#....#.... +...#.....#.......##.........#.# +.##.....#..#.#...#.#...#.#...#. +...........#...#.###..#...#..#. +#.##........#..###.##...####... +.#.....#.#...##...#..#..#...##. +..#....#..#...#.....#.....##... +..###..#.#.....##........#.##.. +.#.#..##........#.##....#..#.## +.####.#..##..#.#..#....##....#. +.##....##...#.#........#....... +....#..#..#...#..#..#..#.#..... +...#......................#.... +#.....#.#....#..#..#.#..#....#. +##.....#.....##..........###... +.#..#..............#...##.#.#.# +...#...#.#.............#.#..#.# +..#.....#.......#......#.#..... +.###.#..#..#..#.#..#.....#..... +.....##..##...##.......#....### +.#........###...##..#....##.... +#....#.#......##..#....#.##..#. +#....#.#...#........##...###... +.#.....#...#.###....#.##.#.#### +###......#....#...#....##..#..# +##....#..###......#...#.#.#.... +..........#......##.#..#....... +.#..#......###.........##...#.. +....#......#....#.........#.#.# +##.#.#...#.#...#...#..#......#. +....#.##.........#..#.....##.#. +........#...#..#.#.#.#.....##.. +..#......#.#.#..#.....##....... +..............#....#....##.#..# +....#.#.....#....#.#.###.#....# +..#..........#..#......#.##..#. +...#...#.#.............#..#.... +#.......#..#..##.........##..#. +..##..#............#.....#..... +....#.#..##...#.#..#.........#. +........#.......#.##....#....#. +...#.....#.#.....#.#....#...... +..#......##.#.............#.#.# +#.#.............#.#.....#...... +.##....##.#.....#....#...##.... +.#.#....##....#.....##......... +...#.....#.....#.....#..#.###.. +.......#....#...##.#...#...#..# +..#.#.......#...###.#...#....#. +.....###..##....###.#.##....... +....#..................##.#.##. +.#.......###.##...#.#.....#.... +....#....##...##.....#.#...#..# +#..#.....#......##...#....#.... +#..##.........#.....#...#...... +...#..##.......##......#..##### +.#..###.###.#.##........#...... +.#...#....#....#.#....#...##... +##........#....#.........##..#. +.#.....##............#.#....... +....#....#...........###.....## +.#......#.#.#..#....#.#.....##. +......#.##.#..##....#.#.#..#... +#....#......#...#..####........ +......#..#..##..#.......#.#..#. +##....##.###.#...#.##.#..#.###. +.#.........#...##...#.#......#. +..#.#...........####.#....##.## +.....#.#..##.#...###...#..#.#.. +...#..#..##.#...#.....#.##...## +..##......##..........#..###... +.#......##.....#.##....#.#.##.# +...#.......##..##.....#....#... +.##...#...#....#..#............ +#..#....#...........#.......... +......#...#.#.......#...#.##..# +..#.###..#.....#.....#..#.....# +....#....#..........##....#..#. +.......##.#.#.#......#....#...# +####..#.###........#..#......#. +#........##.#.#.#.............# +.#......#......#..#.##.....#... +.....##.##......##.#.....#.#.#. +.......##.#.....##.......#.#.#. +.#.#..#.#..#.##...#.#....#.#..# +.#..##....#..#...##.......#..#. +.#.#..#.......#................ +#........#.#.#......#.#.#.#.... +##......#...#..##.#...##.##.... +##.#..#...........##...#..###.. +......#.####...#........#.#.#.. +...#........##..###.#.#...#...# +.#.....##..#......##......###.. +..#.#...#......#..#..##.#.....# +#....#..#.#..........#...#..... +.#......#.##..###..#.#....#..## +.......#.......#..#..#......#.. +..##.....##.#..#..#.....##..... +........#.##...#.#.#..#..#..#.. +...#.######.........#.....#..## +.#.#............#....#......... +#...#....###.#......#.#........ +#.........#....#...##.......... +....#...........#.###.#...###.. +.........#........#.#.#..#...#. +.#.......#.#.....#.#.....#.##.. +.....#.......#.....#.#.#....... +#.##..#..##.......#...#......#. +.###.....##...##.#...##.##.#.#. +...#......##..##............#.# +...#......................#..## +#..#..#................#...#... +#..#....#.#.#...##.......#..#.. +....#.#..###.##...#..#.###..#.. +..#...#....####.#............#. +......#....#.#...#.#.#......... +#...#........#.....##..###.#..# +#....#...#...##...#..#....##... +#..#...#..#.......#.#..##.#..#. +#.#..........#...........##.... +.#...###...#......#.......#.#.# +.........#.........#...#...##.. +##.#..###......##..#.....#..#.. +....##...............#.....#... +.....#.....###.#.....#.#....... +....#..#......###..#..##..#.... +......................#.....#.. +..#..#...##....##....#........# +..#....#...#...#.......#.....#. +...##.#.#.##......#.#.#.#.####. +.###...#..#......#.#..#........ +#..#...##.#..#..##..##....#...# +...#...#..#..#..#........#..##. +.##....#.##.#....#...#.#.#....# +#..#....#..#....#.......##..#.# +...#.#....####...........#...#. +#...#####...#.#..#......#...#.# +.##....#.#.#..#......#..##..... +..........#..#.#.#.....##...... +.....#....#..................#. +.........#...#...#....#..###... +.#.#.#....#.................... +......##............##.###..#.. +#.#...#........####.##..#.#.##. +#........#.#.#.#..#.##.....#... +......####..#.##.......#....#.. +.........#...#...#.....#....... +..##.....#...#...#.....##.....# +....#...##....#.....#..#..##.## +..#.........##...##..###..#.... +#....#.#.........##.###.#...##. +.##...#....#..#..#.#....##..... +##..#..#..#...........#.##....# +....#..........#...#..#.....#.. +........###..#..#.#.#.....##... +#...#...#..###............###.. +..#.....#.#.#..#..#.#..#......# +..#...##..#....#...#......#.... +#....#........##.....#..##....# +#.....#.#.#..#.......##.#.#.##. +..##...#...#.....#..........#.. +##.....#....#......#..........# +......#..#..........#.#..####.. +......#...#............##...##. +..#.......##.......#...###.###. +.#..#.#.#...#..##.#......#.#... +.##.....##.#.#...#.##.........# +#.#.######...........#.#####.#. +........#.##...##....##.#.##.#. +....#......#.....#.....###...## +#..............#.#....#.#....#. +....#..###.#.........##.#.#.... +..#.#.#..##....####..........#. +...#..#.......#................ +...#....#..............#....#.. +.....#...#...#....#.#.#..#...#. +......##.............###.##..## +.#...#.#..#......#..#.##....... +##.....#.....#.##...#....#..... +..#..#.#.#.#.#..........#..###. +##..........#........#....#.#.. +.....#...#........#.#..###....# +.###.#........#.##......#.#...# +#...##....#....#....##.#.#..... +.....#.#............#.......... +..#.##....................#.... +.....#..#..#.#..#.##.......#... +.....###......#......##......## +#.....#.#.......##.......#...#. +.#.#...#......#..###...#.....#. +#.#..#...#..##.....#...#.#..#.. +.....#.#..........#..#......... +.###..##..##.....#...#...#..##. +#...#.#....#.......##..#....... +###...#.#.#..#.......#......#.. +....##........#..........##.... +............#....#...........#. +#..#.#....##..#.#..#......##... +.###....##...#....##..........# +.###........#........###.....#. +...#...#.#......#...#....#..... +.###.......#.........#......... +....##.#......#...###......##.# +.###...#..##.....##.......#.... +.#.#...#..#.##....#........#... |