From 8c6b7ffc7e0e27ddfa1c6ee51a69dbfbd752d8dd Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 6 Dec 2020 17:17:08 -0300 Subject: Add day3 --- 2020/day3.raku | 57 ++++++++++ 2020/day3.txt | 323 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 380 insertions(+) create mode 100644 2020/day3.raku create mode 100644 2020/day3.txt (limited to '2020') 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 @@ +.#....#..##.#..####....#....... +......#..#....#....###......#.# +#..#.....#..............##.#.#. +#.#...#....#...#......##..#..#. +...#..#.##..#..#........###.#.# +...#.#..........#.........##... +...#.#....#.#....#..#......#... +..##.#.....#.......#.###..#..## +..#.......#.......#....##...... +....##........##.##...#.###.##. +#.......#.......##..#......#... +..##.............##.#......#... +...#.####....#.....#...##...... +.............##.#......#....... +..#...#....#......#....#....... +..#....#..#............#....... +##...#..#........##..#......#.. +##........##........#.#.......# +#.......#........#.#..#....###. +.....#..#.#..........##...#.... +..##...#......#.#...#..#...#... +##.##...#......#....#....#...#. +#.......#..#.#..#....#..###.#.# +#.............#.#....#..#.#.... +...#.......###.#.##.##.#...#..# +.##.......##..##...#..###...... +.......#.#.#.#..####..#..#..#.. +...##......#.#.##.###....#.###. +###......###......#.#####..#... +..#........##..#..##.##..#...#. +.....##..#...#..#.##.....#.#... +#......#.##....#..##.#....#.#.. +##.#.##..#................#.... +......#.#....#......##.....#... +..#...##..#..#...#..#.#..#..... +........#.#.#.##...#.#.....#.#. +#.#......#.....##..#...#....... +..#.#......#...........###..... +......##....#....##..#..#.#.#.# +##....#.###...#......#..#...#.. +#.#.##....###...####.......#..# +##...........#.....#........#.# +.##.#..#.....#......#.......#.. +##..##..###....#.........##.... +..#..#..#.##...#.#...#........# +#.##.###...#.......#........... +.........#.................#... +#.##...#.....#..##........#.... +....#.#...##...#...........#... +.#.....#.#..#...##..##.....#... +.#.....####....#..##..#........ +...#..#......##.#..##.#.#.#..#. +.##.#.....#.....#...#.......##. +......#..#..#......#...####.... +.......#......##..#..##.....#.. +......#.#..#...#..#.#.......... +....##.........#............... +.#....#..##.....#....##.##..... +#.#.....#...#....####....#.#... +#.....#....#.#...#............. +...#..#.....#....##..#..#...... +...#.#............#...........# +###.#..#.#......#.....##.....#. +####....#....###.....#..#.##### +.###..#...#.#..#......##.#.#.#. +.....#.##.#....#..##....#..#..# +...#....#...##.....#......#.#.. +....#...#....#...#....#.....#.# +.#.....#.....#.#..#......#..#.. +..#..##....##.##....#.....##... +#..##...#.##...#..#.#.#.....#.. +...#..##.#..#....#.#....######. +..........#..#.....#....#...##. +#.#####.#.###..#.....#......... +#....#......#..#.#.##.##..###.. +..#...###.#.#....##.##...##.... +.......#....#..#...##......#... +...#.#...#..#.....#..##.#...... +###..##...........#............ +..#....#.##....#.#..##...#..... +##....#...#....#.....#.#..##... +..............#.##.#..#..##.### +......#..#..#..#.#....###...##. +.#...#..#.#.#....#..........#.. +..#.#.....#..#...........#.##.. +...#.#......#......#..#..#.#... +...#....#.#.#.....#...#.##..#.. +.#.#..#...#........##.......#.. +##..........#..#...#....###.#.. +#.....###......#..#.#.#....#.#. +..###.......#.#...............# +#....#.....#.#......#..##.##... +#.##.#.#....#..#.#...#.#...#..# +#....#..#...........#.......#.. +...#.####.....#.........###.##. +......#..#.....#..........#..#. +#...#.#..####...#...#.#.##...## +.##.........#......#.#.#....... +.......##...##.##....###...##.. +...#..#....#..#.#.#.....#.#.... +#....#.#.#.......##..###..##... +......#............#.#...#..#.. +#.#.....#......#...#.......###. +...#.#................#...#.... +.....#......#.#..#...##.#.#...# +#....#.#..#..#..##..#.##..#.... +#.................#..#....#.... +..#....#.......####....###..... +.#..#.#.#...###..#...#..###.... +..#..#.#......#.###..........#. +.....#......#.......##....##.#. +.#....#........#.#.##.#........ +#.#..##..#..#.#...####....##... +...#....#.#..#...#..........#.. +.#.....#.##....#...##.......... +....##....#.....#.....#...#.### +.#...##.#.#..##..#...#.#..#..#. +..#.......#.##.....#.#........# +...#...#.....##..#.#.#....#.... +...#.....#.......##.........#.# +.##.....#..#.#...#.#...#.#...#. +...........#...#.###..#...#..#. +#.##........#..###.##...####... +.#.....#.#...##...#..#..#...##. +..#....#..#...#.....#.....##... +..###..#.#.....##........#.##.. +.#.#..##........#.##....#..#.## +.####.#..##..#.#..#....##....#. +.##....##...#.#........#....... +....#..#..#...#..#..#..#.#..... +...#......................#.... +#.....#.#....#..#..#.#..#....#. +##.....#.....##..........###... +.#..#..............#...##.#.#.# +...#...#.#.............#.#..#.# +..#.....#.......#......#.#..... +.###.#..#..#..#.#..#.....#..... +.....##..##...##.......#....### +.#........###...##..#....##.... +#....#.#......##..#....#.##..#. +#....#.#...#........##...###... +.#.....#...#.###....#.##.#.#### +###......#....#...#....##..#..# +##....#..###......#...#.#.#.... +..........#......##.#..#....... +.#..#......###.........##...#.. +....#......#....#.........#.#.# +##.#.#...#.#...#...#..#......#. +....#.##.........#..#.....##.#. +........#...#..#.#.#.#.....##.. +..#......#.#.#..#.....##....... +..............#....#....##.#..# +....#.#.....#....#.#.###.#....# +..#..........#..#......#.##..#. +...#...#.#.............#..#.... +#.......#..#..##.........##..#. +..##..#............#.....#..... +....#.#..##...#.#..#.........#. +........#.......#.##....#....#. +...#.....#.#.....#.#....#...... +..#......##.#.............#.#.# +#.#.............#.#.....#...... +.##....##.#.....#....#...##.... +.#.#....##....#.....##......... +...#.....#.....#.....#..#.###.. +.......#....#...##.#...#...#..# +..#.#.......#...###.#...#....#. +.....###..##....###.#.##....... +....#..................##.#.##. +.#.......###.##...#.#.....#.... +....#....##...##.....#.#...#..# +#..#.....#......##...#....#.... +#..##.........#.....#...#...... +...#..##.......##......#..##### +.#..###.###.#.##........#...... +.#...#....#....#.#....#...##... +##........#....#.........##..#. +.#.....##............#.#....... +....#....#...........###.....## +.#......#.#.#..#....#.#.....##. +......#.##.#..##....#.#.#..#... +#....#......#...#..####........ +......#..#..##..#.......#.#..#. +##....##.###.#...#.##.#..#.###. +.#.........#...##...#.#......#. +..#.#...........####.#....##.## +.....#.#..##.#...###...#..#.#.. +...#..#..##.#...#.....#.##...## +..##......##..........#..###... +.#......##.....#.##....#.#.##.# +...#.......##..##.....#....#... +.##...#...#....#..#............ +#..#....#...........#.......... +......#...#.#.......#...#.##..# +..#.###..#.....#.....#..#.....# +....#....#..........##....#..#. +.......##.#.#.#......#....#...# +####..#.###........#..#......#. +#........##.#.#.#.............# +.#......#......#..#.##.....#... +.....##.##......##.#.....#.#.#. +.......##.#.....##.......#.#.#. +.#.#..#.#..#.##...#.#....#.#..# +.#..##....#..#...##.......#..#. +.#.#..#.......#................ +#........#.#.#......#.#.#.#.... +##......#...#..##.#...##.##.... +##.#..#...........##...#..###.. +......#.####...#........#.#.#.. +...#........##..###.#.#...#...# +.#.....##..#......##......###.. +..#.#...#......#..#..##.#.....# +#....#..#.#..........#...#..... +.#......#.##..###..#.#....#..## +.......#.......#..#..#......#.. +..##.....##.#..#..#.....##..... +........#.##...#.#.#..#..#..#.. +...#.######.........#.....#..## +.#.#............#....#......... +#...#....###.#......#.#........ +#.........#....#...##.......... +....#...........#.###.#...###.. +.........#........#.#.#..#...#. +.#.......#.#.....#.#.....#.##.. +.....#.......#.....#.#.#....... +#.##..#..##.......#...#......#. +.###.....##...##.#...##.##.#.#. +...#......##..##............#.# +...#......................#..## +#..#..#................#...#... +#..#....#.#.#...##.......#..#.. +....#.#..###.##...#..#.###..#.. +..#...#....####.#............#. +......#....#.#...#.#.#......... +#...#........#.....##..###.#..# +#....#...#...##...#..#....##... +#..#...#..#.......#.#..##.#..#. +#.#..........#...........##.... +.#...###...#......#.......#.#.# +.........#.........#...#...##.. +##.#..###......##..#.....#..#.. +....##...............#.....#... +.....#.....###.#.....#.#....... +....#..#......###..#..##..#.... +......................#.....#.. +..#..#...##....##....#........# +..#....#...#...#.......#.....#. +...##.#.#.##......#.#.#.#.####. +.###...#..#......#.#..#........ +#..#...##.#..#..##..##....#...# +...#...#..#..#..#........#..##. +.##....#.##.#....#...#.#.#....# +#..#....#..#....#.......##..#.# +...#.#....####...........#...#. +#...#####...#.#..#......#...#.# +.##....#.#.#..#......#..##..... +..........#..#.#.#.....##...... +.....#....#..................#. +.........#...#...#....#..###... +.#.#.#....#.................... +......##............##.###..#.. +#.#...#........####.##..#.#.##. +#........#.#.#.#..#.##.....#... +......####..#.##.......#....#.. +.........#...#...#.....#....... +..##.....#...#...#.....##.....# +....#...##....#.....#..#..##.## +..#.........##...##..###..#.... +#....#.#.........##.###.#...##. +.##...#....#..#..#.#....##..... +##..#..#..#...........#.##....# +....#..........#...#..#.....#.. +........###..#..#.#.#.....##... +#...#...#..###............###.. +..#.....#.#.#..#..#.#..#......# +..#...##..#....#...#......#.... +#....#........##.....#..##....# +#.....#.#.#..#.......##.#.#.##. +..##...#...#.....#..........#.. +##.....#....#......#..........# +......#..#..........#.#..####.. +......#...#............##...##. +..#.......##.......#...###.###. +.#..#.#.#...#..##.#......#.#... +.##.....##.#.#...#.##.........# +#.#.######...........#.#####.#. +........#.##...##....##.#.##.#. +....#......#.....#.....###...## +#..............#.#....#.#....#. +....#..###.#.........##.#.#.... +..#.#.#..##....####..........#. +...#..#.......#................ +...#....#..............#....#.. +.....#...#...#....#.#.#..#...#. +......##.............###.##..## +.#...#.#..#......#..#.##....... +##.....#.....#.##...#....#..... +..#..#.#.#.#.#..........#..###. +##..........#........#....#.#.. +.....#...#........#.#..###....# +.###.#........#.##......#.#...# +#...##....#....#....##.#.#..... +.....#.#............#.......... +..#.##....................#.... +.....#..#..#.#..#.##.......#... +.....###......#......##......## +#.....#.#.......##.......#...#. +.#.#...#......#..###...#.....#. +#.#..#...#..##.....#...#.#..#.. +.....#.#..........#..#......... +.###..##..##.....#...#...#..##. +#...#.#....#.......##..#....... +###...#.#.#..#.......#......#.. +....##........#..........##.... +............#....#...........#. +#..#.#....##..#.#..#......##... +.###....##...#....##..........# +.###........#........###.....#. +...#...#.#......#...#....#..... +.###.......#.........#......... +....##.#......#...###......##.# +.###...#..##.....##.......#.... +.#.#...#..#.##....#........#... -- cgit v1.2.3-70-g09d2