From afcc6c26e339f8abce972d3a5ea1659ffe1f6c88 Mon Sep 17 00:00:00 2001 From: Nick Thomas Date: Thu, 3 Dec 2020 18:30:42 +0000 Subject: [PATCH] Day 3 --- 03/input | 323 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 03/part1.js | 52 +++++++++ 03/part2.js | 57 ++++++++++ 3 files changed, 432 insertions(+) create mode 100644 03/input create mode 100644 03/part1.js create mode 100644 03/part2.js diff --git a/03/input b/03/input new file mode 100644 index 0000000..49c14b1 --- /dev/null +++ b/03/input @@ -0,0 +1,323 @@ +..#.#...#.#.#.##.....###.#....# +...........##.#...#.#.......... +....#.....#..#.............#... +.#....###..##...#...##...#.#..# +#.......#.........#..#.......#. +...#.##..##...#.#......#.##.#.. +#.#..##.....#.....#..##........ +...#.####...#.##...#........... +.#...#..#..#....#.#.#.#.##..... +##.#..#.##..#......#..##.#.#..# +.#.##.....#.#...............#.# +..##.#.....#.....##..##.#....#. +#..#..........#...##........#.. +#..##.#.#...............#..#... +..#....#...#.......#.......#... +.........#.#.##.#........#..... +#...##....#..#.........#.#...## +...#.#...#...........#..#...#.. +...#..#........#...#........... +.#....##.#...#.#....#....##.... +...#...#......#.#.......#...##. +####..........##....#.......... +#..#........................... +#....#...####..##.#......#.#... +..#..#.....##.....#...#....#..# +#.##......#..##........#....... +..........#.....#...#.#.#....## +....##...##..#........#...#..#. +#..#..#...##..............##... +###.##..##.###...#....##.#..#.. +.#......#.................#.#.. +#.#..#.##.#.#.#.....#.........# +..##......#.......##........#.. +#..............#.##.#.....#.... +............................##. +..#.##......#..........#....#.. +..##.....#..##.#....#.......##. +..#.#.##.#.........#........... +...........##.#.#...#......###. +#....#...#........#.#...#.#.### +..............#...#.....##....# +#...#...#..............#..#...# +.##..#.........#.##.#..#...##.. +.....#.........#..#..#.......#. +.#......#.#.#....##..#...#..##. +#....................#.#....#.. +......#.....##............#.... +.#.....#......####.....#....##. +##.####.#..#..........#......#. +##....................#..##.... +.....#...#.#.##.#.###.....#.... +.#..#...####.#.#...#.#.....#... +#.....##.........##.##.##.....# +....#....##.###.........#...### +.......#........#.##.....#####. +...#.##..#...#...####.....##... +..#....#....#......#......#.#.. +...#.#.#.........#.......#..#.. +.....#...........#.#........##. +..##...#.#.##.#.#.#...###.#.... +..##.............###....#.#.... +#.......#....#..#...#..##..#... +....##..#.......####....#..#.## +##....#...#.#.#...#...#........ +....#.#................#...#... +...#.....#.#.......##....#.#..# +#....##.#...#.#..#.#.........#. +#..##.........##.....#...#..... +....#.....#.#..#..##..##.##...# +#.....#...#.#.#.##....#.#.##... +.#.#........#..##.......#...#.# +..###.....#..#.##....#...#....# +...#..###...#...#.......#..#... +.#....##.......#.#..........##. +...#.#.............##.....##... +..#..#...#.....#...#........... +.#.#......#.##....#.....#...... +........#.#.....#.#...#..#.#..# +#.....#.#.....#.##..#.#....#.#. +..#..###.#.#........#.....##..# +#.#....#......#.#....###..#...# +...#.#....#..#.##.....#...#.... +....##....#.#...#.........#..## +.#......#...#.............#..#. +#........#........#.#.....##... +..##..#.##..#........#......... +.....#...#...#..#.....#.#.##.#. +..#..#..#.........#...#.......# +....#.....#.......#.##.#.##..## +......#.......##...#......#.... +....#....##.......###.#......#. +.....#..#.#........#....#.....# +#...#...#....#...###........#.. +#...........####.......#.#..#.# +..###....#..........#...#.###.. +....#.#.....#....#..#.....#.##. +...##.#..#..#.......#......#.#. +....#......###..#.....#.....#.. +.....#.#.#.....#.##.#....####.. +.##....#.....#.#....##..#...... +#..#.....#..#...#....#.#....... +.##.#..####..#.##.#......#..... +......#....#.......##.##....#.. +...#....#....#..##.......##.### +..##..........##.............#. +.#...#.#...##..##.....#..#..... +....#.#.##...................#. +.......#.#..#....#.....#....... +.#.#..#....####...#.#.##....#.. +.#.##...#..#..#...#.#.......#.. +##.#.....##.........#.......#.. +.##...#.....#.........##.#....# +.............#..#............## +...##.......#.....#.......#.##. +##..##......................... +.##.#........#........#........ +.....#................#.#...... +.............#....#....##....#. +#..##...##...#..#.#............ +.......#...####.#..#..#.....##. +..#.#..#......#.....#.#.#.....# +...#..##........#..#.#....#.#.. +.#.....#..###..#....#.##.#...#. +#.#..#.##.#..#......#.###...#.. +##..#.#..###....##.#...#...##.# +##..#.........#...##......#.... +#.#...#.#..#..........#.......# +.......#.#.......#.....##..#... +........#..##............##.#.. +........##.....#........#..#... +#..##.#..###......##........... +..#.....#.#.#....#...#.#..#..## +#...............#.......#.#.##. +#..#.....#....#............#.#. +...#....#...#....#..#..###..... +..#....#.#.....#..#......##.#.# +.#.#....#..#...#....#........#. +..##....##....#.....#.#........ +.#...#....##..##.....##.....##. +.#...........#....##...##.#.... +...#.....#......###.##.#....... +......#.#..##.#.#....#...#...## +....#...###.##....#.#.....#.... +.......#.....#......#.....##..# +.####.#...##..#....#........... +................###...#....#..# +...#...#.....###.#.##.......#.. +..#....#...##...#.###......#.#. +#...#......#............#.....# +#.........#...............#..#. +...#.##.....#............#..... +........#......##..#..#..#.#..# +....#....#.....#.#.....##..#... +.....#....#..##.....#.......... +.##....#..#...........##....... +#......##.....#...#.....#...... +...#.....#......#.#....#....... +...#................##...#..#.. +........#..........#....#...... +......#....#.#.#...........#.#. +.#............#....##.......##. +#.......#.....#...##.#..##..... +.#.....#.##..#..#....#.#..#.#.# +....#...............###........ +#####...........#..#.......#..# +...#.......#...#.#............# +#...#..#.#...#.#...#.##.....##. +.#..#..#..#.....#....#...#..... +.#...#......#.......#.........# +.#....#.....#...#...#..#....#.. +#....#....#.......#.....##..... +.#...#.#.##.#....#..##........# +..##...#............#.......... +..........#..#..#...#....#..... +..#.......#....#.....##..##.... +.#...#......#...#..###...#...#. +..##...#......#...#.#.#...#.... +.....#..#.#.#.#.#...#....##..#. +##..#..##....#.#........##.#... +.##..#.#...##..#....#..#....... +.....#...#...#..#.#..#......#.. +.#.....##.##..#....####..#....# +......##.................#....# +....##.......###...#.##...##.#. +...#...#.................##.#.. +.#.....##...#...#.....#.....##. +##.........####..#...#...#....# +...##.....#......#.###..#...... +.....###..##.#.......###..##... +#....#...#.#...#...#.#....#..#. +#...#.........##.#.........###. +#....#..###..........##........ +.###.....#.#.....#........##..# +....#.........##..#..#.#.#..#.. +..#......#...........#..##...#. +...#.#..#..#...#.##..#..#.....# +.#...#...#....................# +..#..##..#.............#.....#. +.....###.#.#.#...##..#.##....#. +..#...####..##.#....#...#...#.. +.....#..#........#.#.#..#.##... +#.#.........####..#...#.#...... +..............#..#........#.... +....#........#......#.........# +#..#.##......#.#.......#....#.. +....#..............#.#.#..#.... +#.#......#.....##.......#..##.. +.#.#..........#....#......#.... +.....#.......#.##.....#......## +...#...#.##.............####... +..#....##...#...##..#.#..##.#.. +..#.........##.......###.#..... +..#.........#####..##...#...... +..#.#...#.......#.####......##. +......#.#.#....#......####....# +.###...........#...#..#..#..##. +..#...#..##.##...#.#.##.....#.. +.....#..#....##.......#...#.... +......#.....#.........#..#..#.. +...#..#.........##.....##.#...# +....##...#......#..#.....#..... +....#..#....#....#........##... +##.....#.......#.....#.#.#..#.. +.....#..##.....##.##.#......... +.#.#..##.............#.#....... +......#.##.#.....#.#......#..#. +..........#.#..#....#.#.#.#..## +...##.....#..#...#...#...##.... +........#.#......#..###..#..... +..#.##......#.......#.......#.. +...#....##.##.........#.#...... +......#....#.#.........#......# +.....#...#....#...#......#..#.. +.##...#......#.........#...#.#. +..#.#.#......#....#............ +..#.....##.............#.##.##. +#......#......#...##.......#.#. +##........#.....#.............. +.#.###.................#.#....# +........##.#..##........#.#.... +.......###...#...##.#..#....#.. +.#..#....#..#......##......#... +.#...#....#..........##..##.#.. +.#..###.......#............#... +...#.....###.#..#........#.#.#. +...#....#..#.##..........#.#.#. +.#..##..#.....#...........#.... +#...#...##....#..#....##....... +#..#......#................#... +#..##....#.#..#......#.#.#..... +##.#..#...#.....#.#...#......## +#....#.#.#....#.....##.....##.. +....#...##.#...####.#.#.#.#..#. +.....#.#....#..#.....#..#...... +.........#.#................... +........#.....####......#..#..# +.#.#.##.#...#.#......#...##.##. +.#......#.#.#...#..#.......#... +..#......#.##.##.#.#....#...... +..........#.#...###............ +.##..#..#.#.#..#.....#..#.#.... +......#.......#.#..#.#....#...# +.#.......###......#...#.#.#.... +.............##..#..#...#....#. +....#......#.#...#.#...#...#... +..#....#.......#.#..#..#.#..#.# +.#..#.#...#.....#.#...#####...# +.##............#....#.......... +#.......####...#.#.#........... +...#.......##.#..........#....# +..#.#......#.......##.....#..## +#......#.###..#......#......#.# +##....#..#....#.##....#..#..... +...##...#.#....#.#.......#..... +#...####....#..#.#..#.##....### +.....#..#..........###..#...... +.#..#..#...#....#.##..#..#..... +#..#.....#....#..#.##...##..... +.....###.#..#.......#...###.##. +#..#........#.#..#.#.........#. +....##........................# +.#....#.#.#.#.#...#......#....# +#....#...#.##.......#.#.###.... +..........###..##....#..##.#... +...##..###...#.#.#.......##...# +##.#...#..#.....###....#....... +..#..##....###........##....### +.....##..#...#..#.....#..#....# +#................#....#...#..## +#....#.#....#..###.#.#...#..#.# +........##.#...#.#.#.#...#..... +..#..###....#......##.#...##... +..#..##....#.##..#.....#.....#. +.#.#...#.....#..#..#......##.#. +........#.#...#..##....#..#.... +...##...#...#...#...##...##..#. +.......#..#..#....#.#..#...##.. +.#.....#.##........#...#.#..... +##.#..#....#.#....#.#....#...#. +..#.#......#.......##...#....#. +#.#..####..#........#.......### +....#.......#.......##.#...#.#. +..#..#.#.............#..#...... +........###.....##....#.......# +...#.....#...#...#....#.###.... +#...##.#........#..#...##..#..# +...##..#....#....#.#.#...#.#... +#......#.....#....###......##.. +.....#.........####...##..#.... +.......#...##...#..#..#.#...... +.#.#....#.....#.......#........ +...##...#....##..#.....###..... +.#....#........##......#....#.# +.........#.#.#.#...........#.#. +....#.#..##......#.#.#..##..... +.........#.....##....#......... +....#.............#...........# +...#..##........#.....###...... +#....#....#......#..#..#..#.#.. +#......##.....#..#....#..#.#... +#..............#....#.#....###. +..##..#..#...#...##........##.. +..#.##....#..#......###..#..... diff --git a/03/part1.js b/03/part1.js new file mode 100644 index 0000000..5b05fb7 --- /dev/null +++ b/03/part1.js @@ -0,0 +1,52 @@ +const fs = require('fs') +const readline = require('readline'); + +const readInterface = readline.createInterface({ + input: fs.createReadStream('input'), + console: false +}); + + +// array of arrays of bool. Coordinates are [y][x]. True = tree. +let map = []; + +readInterface.on('line', function(line) { + let row = []; + + line.split('').forEach(function(char) { + if (char == '.') { + row.push(false); + } else if (char == '#') { + row.push(true); + }; // ignore any other character + }); + + console.log(line); + console.log(row); + + map.push(row); +}); + +readInterface.on('close', function(line) { + let treesHit = 0; + let x = 0; + let y = 0; + + while (y + 1 < map.length) { + x += 3; + y += 1; + + if (x + 1 > map[y].length) { + x -= map[y].length; + } + + if (map[y][x]) { + treesHit++; + } + + console.log(x, y, map[y][x]); + } + + console.log(treesHit); +}); + diff --git a/03/part2.js b/03/part2.js new file mode 100644 index 0000000..b9fc7e0 --- /dev/null +++ b/03/part2.js @@ -0,0 +1,57 @@ +const fs = require('fs') +const readline = require('readline'); + +const readInterface = readline.createInterface({ + input: fs.createReadStream('input'), + console: false +}); + + +// array of arrays of bool. Coordinates are [y][x]. True = tree. +let map = []; + +readInterface.on('line', function(line) { + let row = []; + + line.split('').forEach(function(char) { + if (char == '.') { + row.push(false); + } else if (char == '#') { + row.push(true); + }; // ignore any other character + }); + + map.push(row); +}); + + +readInterface.on('close', function(line) { + let totals = []; + + [[1,1], [3,1], [5,1], [7,1], [1,2]].forEach(function(step) { + + let treesHit = 0; + let x = 0; + let y = 0; + + while (y + 1 < map.length) { + x += step[0]; + y += step[1]; + + if (x + 1 > map[y].length) { + x -= map[y].length; + } + + if (map[y][x]) { + treesHit++; + } + +// console.log(x, y, map[y][x]); + } + + totals.push(treesHit); + }); + + console.log(totals.reduce((a,b) => a * b)); +}); +