Created
December 4, 2020 14:15
-
-
Save nicknapoli82/d6c5b0751b289d5b32e137d433d7fca9 to your computer and use it in GitHub Desktop.
AOC Day 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const beginTime = process.hrtime(); | |
| let input = ["....#...##.#.........#....#....", | |
| "#.......#...#...#.#............", | |
| "#..#..#.#.##....#.#........#...", | |
| "........##...................#.", | |
| "........#...##...#.#.###.......", | |
| "##............#...#.....#.##...", | |
| "...........#....###...#.....#..", | |
| ".......#......#..##..#.....#...", | |
| "..#.#..#....#.........#...#..#.", | |
| ".........##......#.....##..##..", | |
| "........#.....#....#..##......#", | |
| "..#..#.......#..............#..", | |
| ".....#.#.......................", | |
| ".#.#....#.........#............", | |
| ".......#.....#.###.............", | |
| "......##......#...........#..#.", | |
| ".#...............##...#........", | |
| ".....#..##........###.........#", | |
| "#...........#..#............#..", | |
| ".........#....#..#.#......#....", | |
| ".......#.........#..##.........", | |
| ".##.....#..................#...", | |
| "....#............#.#....#.....#", | |
| "..#....#...##....#...#.#...#...", | |
| "..........#................#.#.", | |
| "#...#.#.#.####..#.#..........#.", | |
| "..#...#.##......#...........#..", | |
| "..#.....#...#.......#......#..#", | |
| "..............#.......#........", | |
| ".#..#..........#.....#...#..#.#", | |
| "#........#...#......#.......#..", | |
| "#..................#...........", | |
| "..#...#........#...#..#........", | |
| "..............#.....#.....#..#.", | |
| "#.#.......#..............##.##.", | |
| "....#.#.....##....#...........#", | |
| "......#....#...#..#.......#....", | |
| "....#..#.#.....#..##.....#....#", | |
| "...........#.......#.#.#.......", | |
| "#.......#..##........#..#......", | |
| ".........#.##..#..............#", | |
| "...........#............###.#..", | |
| "..#.....#.....##...#.........#.", | |
| "....##............##........#..", | |
| ".....###..........#......##....", | |
| "#...##..#..#..........#........", | |
| "....#.....#.......#..#.#...##..", | |
| ".#....#........#.#.........#.#.", | |
| "##...#.#.....#......#..........", | |
| ".....##.....#....#.....###.#..#", | |
| "..............#..###..#...#..#.", | |
| "....#...#....#.............#.#.", | |
| ".#.........#.....#........#.##.", | |
| "....#.........#..........#.....", | |
| ".......#........#.#.#..........", | |
| "#........##....#.........#.....", | |
| "..##..........#....#.#...#....#", | |
| "#...#.#......#..##..........#.#", | |
| ".....#..#...#..#...............", | |
| "#...#..............#...........", | |
| ".#...#....#..##.....#....#.#...", | |
| ".#...#.......#...#..#.##....#..", | |
| "#....#........#....#...#.......", | |
| "#..#......#.....#.....#..##....", | |
| "......#.#....##....##..#...#...", | |
| "..#....#.#.###..............#..", | |
| ".#.##.......#.#.#..#...#..#....", | |
| "..#..........#.#....#..#.#....#", | |
| "..........#...#...#..........#.", | |
| "..........#.....#.#..#..#....##", | |
| ".#.#...##...#...........####...", | |
| "........##..#.#..........#.##.#", | |
| "#......###...........#...#.....", | |
| "..#.#....##.........##....#....", | |
| "#....#.##..##..#..#.....#.....#", | |
| ".##.....##....##....#.......#..", | |
| "#...#.....##....#..........#...", | |
| "............#.#.##....#....#...", | |
| "....#............#.....#......#", | |
| "....................#..........", | |
| "..#....................#..#....", | |
| "....#.....#........#..##...#...", | |
| "#.....#.#....................##", | |
| ".#....#.#.#...#..........#....#", | |
| "....#...#......#...#.....##...#", | |
| ".....#.........................", | |
| ".......#..#.#...#...#...#.....#", | |
| "...#......#.##.#...#..#...##.#.", | |
| "...........................#..#", | |
| "..#.#.....#........##..........", | |
| "....#...##........#.#.#..#...##", | |
| "..##.....#..###.........##.##..", | |
| ".#..#.....#...#.............#..", | |
| "#..............##...#....##....", | |
| ".##......#.#............#......", | |
| ".............##...#.#.......#..", | |
| ".........#..#..#...............", | |
| "........##......#....##........", | |
| "...#.........#.#.#.............", | |
| "#..........#......#......#..#..", | |
| ".............##.#.#..#.#.#...#.", | |
| ".....#.........#...............", | |
| "..##.#..#.....##..#........#.#.", | |
| ".#..........#.#.......#......##", | |
| ".#........................#....", | |
| "#....#....#...#..#......#......", | |
| "........#.......#......#.....#.", | |
| ".....#....##..#...###...#....#.", | |
| "....#.........#....#......#....", | |
| ".............#...#....#.......#", | |
| ".....#.........#..#.#..........", | |
| ".........#..#........#.#.#.....", | |
| "......#.##......#....#.#.##.#..", | |
| ".#...#.#...#...#.#......#....##", | |
| ".#................#......#.....", | |
| "#.#.#...............#..........", | |
| ".....#.#.......#...#........#..", | |
| "#...#.#.#.##..#...........#..#.", | |
| ".............###.........#....#", | |
| ".#.....#.......##....##.......#", | |
| "....#...#.......#.##.....#.....", | |
| "...........##.........#...#....", | |
| "..............#.#..#.....#..#..", | |
| "#.#...#..#.#.........#......#.#", | |
| "#.##.....##....#........#.#.#.#", | |
| "##.#.###.........##.......#..#.", | |
| "#.....#.....................#..", | |
| ".........##........#...........", | |
| ".###........##....#...#........", | |
| "....#.#........##...........#..", | |
| "..........#.....#..........#..#", | |
| "......#..............#......#..", | |
| ".....#...#......#...#...#......", | |
| "..........#.#..#....#...#..###.", | |
| "#..##........#................#", | |
| "..#............................", | |
| ".....#.........#.#.............", | |
| "........#...#.....#...##......#", | |
| "..#........#................#..", | |
| "......#....#..#......#.........", | |
| "...........##....#..#.#........", | |
| ".....#.............###.........", | |
| "#............#......#..#.......", | |
| "..#..#.................#..#..##", | |
| ".......#......#.....#........#.", | |
| "....................#..#.##...#", | |
| ".#..##...............##...#....", | |
| "...#...#....#........#.........", | |
| ".....##...#.....###............", | |
| ".###.........#........#.....##.", | |
| ".............#...#.............", | |
| "...#.#...............#..##..#.#", | |
| "...#...............#..#.....#..", | |
| "....#.#..................#...#.", | |
| "..........#...........#.#...###", | |
| "#...#......#................#..", | |
| "...#.#.......#...#......#.##...", | |
| "......#..........#.............", | |
| "##.......#.##.#...........#....", | |
| "......#...#.#.....#............", | |
| ".#.....#.....#.....#.........#.", | |
| "..................#............", | |
| ".#.#.#.....#......#.##.........", | |
| ".......#..##.##......#..#....#.", | |
| "...#.#.#......#...#........#...", | |
| "..#............#......#.......#", | |
| "..#......#........#.........#..", | |
| "..#..#.#.#.....#.............#.", | |
| "..#.#..##......#...#...##......", | |
| ".##...#....##.#.#...........#..", | |
| "..............#..#...#....#....", | |
| ".......#.#........#............", | |
| ".....##..###........#..........", | |
| "......................#........", | |
| "..##....#....#.................", | |
| ".##.#.###.#........#.##..#...#.", | |
| "##................#...........#", | |
| "....#..##.....##...............", | |
| ".#.....#..#............#.....#.", | |
| "#.........#..............#.....", | |
| "...##.#......#...#.............", | |
| "................#..............", | |
| "...#.....#....##...#..#....#...", | |
| "..............##..#...#.##..#..", | |
| "......................#..#....#", | |
| ".......#....#..#.##.........#.#", | |
| "#...#........##.......#........", | |
| "...##...............#.....#....", | |
| ".##...##...#...................", | |
| ".........##.#...#.........#....", | |
| "............#............#..#..", | |
| ".............................#.", | |
| "....#.#....#...................", | |
| "......#......#...#..##.........", | |
| "#........#.#.#.#.#......#....#.", | |
| ".#.........#.#...#......#..#.#.", | |
| "..............#....##.........#", | |
| ".#.......#..#....#.#.#....#....", | |
| "...###.#.#..#...#....#....#....", | |
| "#........#....................#", | |
| "......#...##.###..#..##...#....", | |
| ".....#........#.......#........", | |
| "#..#...........#.#.............", | |
| "....##.#...#..##............##.", | |
| "#.#..##..#...#...#.....#.......", | |
| "..#.............#.##..#...#.##.", | |
| ".#.....##.#..#...#...........#.", | |
| "....#...#....................##", | |
| "....##......#.###......#......#", | |
| "...#...#.........#..#.##....#..", | |
| "#......#..#....###.........#...", | |
| "#...........##.............#.#.", | |
| "#..............##....#......#..", | |
| ".........#...#.#...#...#.......", | |
| "....#....#............#.......#", | |
| "........#...#....#......##.....", | |
| "..........#.#..#.........#.....", | |
| "#........#.##....##......#.....", | |
| "...#.......#...................", | |
| "###...#...#..#.##....#.....#...", | |
| "........##..........#.##..#....", | |
| ".....#......#..#.....#.....#.#.", | |
| "...#..#..##..###.....##.#......", | |
| "#..#......##...#............#..", | |
| "#............#....#..#.........", | |
| "#........#.......#......#..##.#", | |
| "...#.#.........#.#.............", | |
| "#..............#..............#", | |
| "#.#......#..........##.........", | |
| "#..##...........#..##...#......", | |
| ".....#.#.....#......#.....#.#.#", | |
| ".#.##...#...##...........#....#", | |
| "#.............#........#.......", | |
| "..##.............#...#.........", | |
| "....#.#......###....#..........", | |
| "...#..#.....#..##.#....#...#.#.", | |
| ".............##................", | |
| "#.#............#........#..#.#.", | |
| ".#......#.....#...........#....", | |
| "...#.........#...........#.##..", | |
| ".....#...#.....#..#..........#.", | |
| "........#.#...............#.#..", | |
| ".......#..#..#.....#.......##..", | |
| ".#...#...#..#...##...#.........", | |
| "..........##....#..#.##..#.....", | |
| "....#.................#...#....", | |
| ".........#...#......#....#....#", | |
| ".........#..#...#.##........##.", | |
| "#.#....##.......#.#............", | |
| "##.......##..................#.", | |
| "......#...#......##............", | |
| "##.#...#.#...........#..#......", | |
| ".........#.........#..#.#...#..", | |
| ".#...#.......#.#...###.........", | |
| "................#.#.....#......", | |
| "..#...#.....#........#.........", | |
| ".........##.###.#.#.....#...#..", | |
| "#..#..........#....#.#...#...##", | |
| "##.#.#....#..##.............#.#", | |
| ".###....#..#...............##..", | |
| "............#......#.#.#....#..", | |
| "........#...#..#...#...........", | |
| "##.........#................#..", | |
| "...###...#.#..#...#..........##", | |
| "...#......#......##........#...", | |
| ".......#............#..........", | |
| ".....#.....##....#.....###.....", | |
| ".#...#...#.....#..#..#....#..#.", | |
| "#.#........#..#.......##...#.##", | |
| ".....#.....##..#.##........#..#", | |
| ".....#...#...........#.........", | |
| "..#....#.#...#..#....##...#...#", | |
| "...........#...##.........#....", | |
| "..#....#....##........#.####...", | |
| "#.............#.#.............#", | |
| "...................#.....#.#..#", | |
| ".#....#.#.............#.#......", | |
| "#...........#............#.#...", | |
| "..#.........#.#....#.......##..", | |
| "#....####......#...#......#....", | |
| "....##....#...................#", | |
| "....#.##....#.............#....", | |
| ".........##........#.....#..#..", | |
| "............#...#..............", | |
| "............#..##....#.....##.#", | |
| "............#.....#......#.....", | |
| "........#..#........##.#.......", | |
| "...#.#........#..............#.", | |
| "............#.........#..#.#...", | |
| "................#.............#", | |
| "..##..........##......#.#......", | |
| "..#..#.##....#.........#...#...", | |
| "...........##...#.#.#..........", | |
| ".#.#.......#.#...#.........#...", | |
| ".........#..#........#..#.#....", | |
| "..........##..#.##....#....#...", | |
| "....#...............#.......#..", | |
| "##..........##.................", | |
| "....#.#.#.....#..........##.#..", | |
| "..............#.##..........##.", | |
| "##...............#...#..#......", | |
| "..#..#..........#......#.......", | |
| "#...#..##.#.#..................", | |
| "....#....##......##.#...#....##", | |
| ".#...#.#....##.............#..#", | |
| "................#......###.....", | |
| "..#..#.............#.#.......#.", | |
| "..#..................#.......#.", | |
| ".....#.......#....#.##...#.##..", | |
| ".....##.......#......#..#......", | |
| "#..#.......#........#..........", | |
| "..#...#..#....#.........#......", | |
| "#..#..#......##..#.##....####..", | |
| "......##.#.....#..#.......#....", | |
| ".##...#.....#..#...#.#.........", | |
| "#.....#........###....#...#..#.", | |
| ".#....#.#..#......#............", | |
| ".........#..#..#.....#........#", | |
| "..#.......#..........#..#......", | |
| "......#.......##.#....#.#.#....", | |
| ".#............#.....#.......#..", | |
| "...#..#...............#........", | |
| ".....#........................."]; | |
| function generateToboggan(right, down) { | |
| this.right = right; | |
| this.down = down; | |
| this.traverseHill = () => { | |
| let hits = 0; | |
| for (let offset = 0, slope = 0; | |
| slope < input.length; | |
| offset += this.right, slope += this.down) { | |
| if (offset >= input[slope].length) | |
| offset -= input[slope].length; | |
| if (input[slope][offset]) | |
| hits++; | |
| } | |
| return hits; | |
| }; | |
| return this; | |
| } | |
| const directions = [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]; | |
| const mapTrees = (MT) => MT.map((c) => c === '.' ? 0 : 1); | |
| for (let i in input) { | |
| input[i] = mapTrees(input[i].split('')); | |
| } | |
| let treesHit = []; | |
| for (let tobogganRun of directions) { | |
| treesHit.push(generateToboggan(tobogganRun[0], tobogganRun[1]).traverseHill()); | |
| } | |
| console.log(treesHit); | |
| console.log(treesHit.reduce((a, i) => a * i)); | |
| const endTime = process.hrtime(beginTime); | |
| console.log('\nRunning Time: ' + endTime[0] + ' seconds ' + endTime[1] / 1000000 + ' ms'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hey can u please tell me what's this? I am interested in it. Is it a game or something?