Skip to content

Instantly share code, notes, and snippets.

@nicknapoli82
Created December 4, 2020 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicknapoli82/d6c5b0751b289d5b32e137d433d7fca9 to your computer and use it in GitHub Desktop.
Save nicknapoli82/d6c5b0751b289d5b32e137d433d7fca9 to your computer and use it in GitHub Desktop.
AOC Day 3
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');
@aneeqakbar
Copy link

hey can u please tell me what's this? I am interested in it. Is it a game or something?

@nicknapoli82
Copy link
Author

nicknapoli82 commented Dec 29, 2020

@skipastyyyy
Just for fun. Just a thing for Advent of Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment