feat: complete Advent of Code 2020-12-03
This commit is contained in:
		
							
								
								
									
										2
									
								
								day_3/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								day_3/.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
/.idea
 | 
			
		||||
/cmake-build-debug
 | 
			
		||||
							
								
								
									
										6
									
								
								day_3/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								day_3/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
cmake_minimum_required(VERSION 3.19)
 | 
			
		||||
project(day_3)
 | 
			
		||||
 | 
			
		||||
set(CMAKE_CXX_STANDARD 20)
 | 
			
		||||
 | 
			
		||||
add_executable(day_3 main.cpp)
 | 
			
		||||
							
								
								
									
										323
									
								
								day_3/input.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										323
									
								
								day_3/input.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,323 @@
 | 
			
		||||
...#..............#.#....#..#..
 | 
			
		||||
...#..#..#..............#..#...
 | 
			
		||||
....#.#.......#............#...
 | 
			
		||||
..##.....##.........#........##
 | 
			
		||||
...#...........#...##.#...#.##.
 | 
			
		||||
..#.#...#....#.....#........#..
 | 
			
		||||
....##.###.....#..#.......#....
 | 
			
		||||
.#..##...#.....#......#..#.....
 | 
			
		||||
............##.#...#.#.....#.#.
 | 
			
		||||
..........#....#....#.#...#...#
 | 
			
		||||
..##....#.#.#......#.........#.
 | 
			
		||||
#.#.........#..............##..
 | 
			
		||||
....##.##......................
 | 
			
		||||
....##..#...........#..........
 | 
			
		||||
..#..#.#........##....#......#.
 | 
			
		||||
..............#..#....#.....#..
 | 
			
		||||
.............#...#.....#...#...
 | 
			
		||||
.#...........#..........#...#..
 | 
			
		||||
.#......#.......#......#.......
 | 
			
		||||
#..#.............#..#....##.###
 | 
			
		||||
........#.#...........##.#...#.
 | 
			
		||||
......#..#.....##......#.......
 | 
			
		||||
.....#.....#....#..............
 | 
			
		||||
#...##.#......#......#...#.....
 | 
			
		||||
...........................#...
 | 
			
		||||
...#....................#.....#
 | 
			
		||||
..#.....#...#.....##.....#.....
 | 
			
		||||
....................#......#..#
 | 
			
		||||
.......#.....##......##....#...
 | 
			
		||||
#........##...#.....##..#...#..
 | 
			
		||||
........#..#.#......#..###..#.#
 | 
			
		||||
##.....#.............#.#....#..
 | 
			
		||||
..#.................#....######
 | 
			
		||||
.#.#..#.....#.#..........#.#...
 | 
			
		||||
.........#....#...#............
 | 
			
		||||
........#..#.....#.............
 | 
			
		||||
............#.#.............##.
 | 
			
		||||
...#....#..#......#............
 | 
			
		||||
.##....#.....#...#.#...........
 | 
			
		||||
..#..............#...........##
 | 
			
		||||
.....#.#.##...#................
 | 
			
		||||
..........#..#.#..........##..#
 | 
			
		||||
..#....#...#...#.....######....
 | 
			
		||||
....#.#..#........#....#.###...
 | 
			
		||||
.......................#.......
 | 
			
		||||
..#.....#.##................#..
 | 
			
		||||
.....#......#..#.....#........#
 | 
			
		||||
.#...###.......#.#.........#..#
 | 
			
		||||
............#..................
 | 
			
		||||
..#.........##.........##......
 | 
			
		||||
#...........#.#.......###.#....
 | 
			
		||||
.#...#.....#.........###.....#.
 | 
			
		||||
.#............#........#..#....
 | 
			
		||||
...##.#......##................
 | 
			
		||||
........#...#...#...#..........
 | 
			
		||||
.......#.##......##.#..........
 | 
			
		||||
....##.......#..#....#....#....
 | 
			
		||||
......#.........###........#...
 | 
			
		||||
#....#....####....##......#....
 | 
			
		||||
......................#....#.#.
 | 
			
		||||
...#.#.#....#.#...#...#......#.
 | 
			
		||||
......#.....##.#...........###.
 | 
			
		||||
#........#.........##......#.#.
 | 
			
		||||
....##.....#.....#..#..........
 | 
			
		||||
......#...#...#.........#...##.
 | 
			
		||||
..#........#..................#
 | 
			
		||||
.........#..##.#..#..#...#.#..#
 | 
			
		||||
.....#.....#...#.....###.....##
 | 
			
		||||
.............#....#...#........
 | 
			
		||||
..........#.#.#...#..#...#....#
 | 
			
		||||
#...............##.......#.....
 | 
			
		||||
#...#.............#..#...#....#
 | 
			
		||||
..#...#...##...##...#..#.......
 | 
			
		||||
..#..#........#.#...........#..
 | 
			
		||||
.....#.....#..................#
 | 
			
		||||
....#....##....###..###...##...
 | 
			
		||||
..#......###.........##....#.##
 | 
			
		||||
.......#.##...#.......#..#.....
 | 
			
		||||
...#.#.#.#.....##..#..#........
 | 
			
		||||
................##....#.#......
 | 
			
		||||
..#...#...#...#.....##.#...#..#
 | 
			
		||||
..#..#.....#..##....#....#.....
 | 
			
		||||
.###...#......#........#.....##
 | 
			
		||||
##......#..#........#..........
 | 
			
		||||
....#...#..#....##..#......####
 | 
			
		||||
.#.....##....#..........#......
 | 
			
		||||
.#...#....#.........#...#....#.
 | 
			
		||||
.....#..#.#..#......#..##....#.
 | 
			
		||||
...#.##...#...#........#......#
 | 
			
		||||
.#..#...#.#..#.........#...#...
 | 
			
		||||
#....#......##.....#.......#...
 | 
			
		||||
..##............##..#.#.#...#..
 | 
			
		||||
##.......#.......##............
 | 
			
		||||
#......#.##........#...#...#...
 | 
			
		||||
.#.#.......##.........#..#.#...
 | 
			
		||||
.............##.#........#.....
 | 
			
		||||
.#..#...###...#..#.............
 | 
			
		||||
.....#...#..#....#.......#.....
 | 
			
		||||
#.#.........#.#.#...#...#.#....
 | 
			
		||||
.....#.......#.##.##...#....#..
 | 
			
		||||
.#.##..#.....#...#.#.#.#.#..#..
 | 
			
		||||
..........#...................#
 | 
			
		||||
.....#.#.#...##.........#..#..#
 | 
			
		||||
.#..#....##......#...#.........
 | 
			
		||||
.##......#......#...#........#.
 | 
			
		||||
.....##.#......#............#.#
 | 
			
		||||
.#.....##..#...........##......
 | 
			
		||||
.....#......#.......##....#....
 | 
			
		||||
..#..##..........#.#..........#
 | 
			
		||||
#.#.......##..#..##.#....#.....
 | 
			
		||||
.......#..#.#.......##......#.#
 | 
			
		||||
....#...##...#..............#..
 | 
			
		||||
.....#.........#......#...##...
 | 
			
		||||
#.........#........##..#.....#.
 | 
			
		||||
.#.#..#.....##.......#......#..
 | 
			
		||||
........#..#....#.....###..#...
 | 
			
		||||
#.#..#.#..........#............
 | 
			
		||||
..#......##..#....#.........#..
 | 
			
		||||
#..............................
 | 
			
		||||
.......#............#..#..#.#..
 | 
			
		||||
.#.....#.#....#..#.##.#........
 | 
			
		||||
.......#.###.#........##.#..#..
 | 
			
		||||
..............#....#.....##.#..
 | 
			
		||||
#..............#....#.###......
 | 
			
		||||
.#..#..#...###............#...#
 | 
			
		||||
.#.##...#....#..#...#...#......
 | 
			
		||||
......##..#..#......#..#....#..
 | 
			
		||||
.........#.......##............
 | 
			
		||||
...........##...#..#....####...
 | 
			
		||||
.#..................#..........
 | 
			
		||||
#...#..#..................#....
 | 
			
		||||
..............#.....##.....#...
 | 
			
		||||
..#.#..#...##..#.....#.....#..#
 | 
			
		||||
....#....#.#.........#.....#...
 | 
			
		||||
.#.......#...#....#...#.#..#..#
 | 
			
		||||
#.........##.....##.......#...#
 | 
			
		||||
#..#............#....#........#
 | 
			
		||||
..........##...#......#....#...
 | 
			
		||||
.......#..##...............#...
 | 
			
		||||
#............#.#.#.....#.......
 | 
			
		||||
.#........##...#...............
 | 
			
		||||
..##....#.....#..#.##.#......#.
 | 
			
		||||
.#...#.............#...#.....#.
 | 
			
		||||
...##....#.......#......#.#..#.
 | 
			
		||||
#......................#..#.##.
 | 
			
		||||
...#..........#..#.........#...
 | 
			
		||||
..#......#.......#.#....#......
 | 
			
		||||
....#............#...#......#..
 | 
			
		||||
.....#..#..##...#...#.........#
 | 
			
		||||
.....#......#....#....#........
 | 
			
		||||
.............#..#..........#...
 | 
			
		||||
....#..............#.....#.#...
 | 
			
		||||
....#.................#.#...#.#
 | 
			
		||||
.........#.#...........###.#.##
 | 
			
		||||
#...........#..##.#....#.##.#..
 | 
			
		||||
#.#.....#......................
 | 
			
		||||
##.#.........#....##.#.#..#.#..
 | 
			
		||||
#..........#.#.#.#.#..#..##..#.
 | 
			
		||||
..#...#..###.........#......#..
 | 
			
		||||
.....#......#..#.#............#
 | 
			
		||||
...........#...#.#.#.###....#..
 | 
			
		||||
#....#..#.......##.#.......##..
 | 
			
		||||
..............#.....##.#.......
 | 
			
		||||
.#.....#.#..#.........#.#.#..#.
 | 
			
		||||
..#..#..#..#................#..
 | 
			
		||||
...........#..#.#...#.........#
 | 
			
		||||
.#..#..#...#........#...#.#..#.
 | 
			
		||||
...#.#..#......#..#............
 | 
			
		||||
........#......##.....#....#...
 | 
			
		||||
#...#......##.#.#..............
 | 
			
		||||
.#........................#....
 | 
			
		||||
#.#.....#.##.....#..#.#........
 | 
			
		||||
#..........##.#.......#....#..#
 | 
			
		||||
#...#..#..#.....#....#....#....
 | 
			
		||||
#...........#..#.#....##.##....
 | 
			
		||||
##......#..#........#.......##.
 | 
			
		||||
#........#..#...#..........#...
 | 
			
		||||
...#...#......##....#.#........
 | 
			
		||||
...##..#..#.##....#...#........
 | 
			
		||||
#.#..#....#...#........#.......
 | 
			
		||||
..........#.......#..........#.
 | 
			
		||||
......##...#....###...#....#...
 | 
			
		||||
........#..#.....#......#......
 | 
			
		||||
....#.........##...#..##......#
 | 
			
		||||
....#...........#.#..#.#.#.#..#
 | 
			
		||||
..#......#..#......#........#.#
 | 
			
		||||
#..#....#.....#.............#..
 | 
			
		||||
............................#..
 | 
			
		||||
#...#.#.....#...#....#....#....
 | 
			
		||||
........#...#...#...#...#......
 | 
			
		||||
.###........#....#.##.....##.#.
 | 
			
		||||
.........#.....#..........#....
 | 
			
		||||
.#.........#....##.#.....#.....
 | 
			
		||||
#..#....................##.#...
 | 
			
		||||
..##.#.............#....#.#....
 | 
			
		||||
..#.#........#............##.#.
 | 
			
		||||
#........#...##.....#...#.....#
 | 
			
		||||
.........#.#..........#....#..#
 | 
			
		||||
...###.#..#.#......#.#.....#...
 | 
			
		||||
......#.....#..#...#........#..
 | 
			
		||||
.......#...#.....#....#....#..#
 | 
			
		||||
.#.#........#......##.......#..
 | 
			
		||||
#.................###..........
 | 
			
		||||
#........#.#..#....#..#........
 | 
			
		||||
..##....#.#...##...#...##....#.
 | 
			
		||||
...#.#......##...#.....#..#....
 | 
			
		||||
#..#........#...###....#.......
 | 
			
		||||
##.#....#..#.#..........#......
 | 
			
		||||
....#...###...#.....#........#.
 | 
			
		||||
..#.#........#....##.#.........
 | 
			
		||||
......##.##.................##.
 | 
			
		||||
.#....##...#.#..#.#............
 | 
			
		||||
.#...###........#......#.......
 | 
			
		||||
##..#.#......#..#..#...#.......
 | 
			
		||||
.......##..#....#........#....#
 | 
			
		||||
......#..........#.............
 | 
			
		||||
....##..##..#......#.#.........
 | 
			
		||||
.....#....................##...
 | 
			
		||||
...###.....#.....#...#.#.##.#..
 | 
			
		||||
....#.#..#.......#..#......##..
 | 
			
		||||
.......#.#..#.##.#...#......#..
 | 
			
		||||
...#.#....#.#...#..##...#...#..
 | 
			
		||||
#.##...#....#..#.............#.
 | 
			
		||||
...#...#...#.......#..........#
 | 
			
		||||
.#..#.............#..##.#......
 | 
			
		||||
....#.......#..............#.#.
 | 
			
		||||
..................#..#.....##.#
 | 
			
		||||
.#...#..#......#..........#...#
 | 
			
		||||
..#.#.....#..#....#....#####.#.
 | 
			
		||||
.......###.......#....#....#...
 | 
			
		||||
......#.#........#...#.........
 | 
			
		||||
......#..#.#.#....#.#.#....##..
 | 
			
		||||
.#...#.#...##.#......#.........
 | 
			
		||||
#....#..##....#.#.......#....#.
 | 
			
		||||
..##.#.....#.....#.........#...
 | 
			
		||||
......#......#....#....#.....#.
 | 
			
		||||
...##.....#....#......#......#.
 | 
			
		||||
......#......##............#.#.
 | 
			
		||||
.##.#.......#....#...#....#....
 | 
			
		||||
....#..#..#...##.......#..#....
 | 
			
		||||
....#....#...#.#........#..#...
 | 
			
		||||
....#.....#..........#..#......
 | 
			
		||||
....#....#...#.....#..##.....#.
 | 
			
		||||
##...#..##......#....##..#..#..
 | 
			
		||||
.....##.##..............##.....
 | 
			
		||||
#.#....#.##..#....#...##.......
 | 
			
		||||
..#.....##.....#.....######...#
 | 
			
		||||
...#.....#.#.#......#......##.#
 | 
			
		||||
...........##.............#....
 | 
			
		||||
...##......#..#......#...#.....
 | 
			
		||||
....#.##......#..#....#.#..#...
 | 
			
		||||
.#..#....#...#..#.....##.......
 | 
			
		||||
.....#..#.................#..#.
 | 
			
		||||
................#..#...#......#
 | 
			
		||||
...##....#.....#..#....##......
 | 
			
		||||
....##...............##...#....
 | 
			
		||||
......#..........#..##.........
 | 
			
		||||
.......###.......#.........#..#
 | 
			
		||||
......................#....#.#.
 | 
			
		||||
#.#.....#...##............#....
 | 
			
		||||
........#......##......#.....#.
 | 
			
		||||
...#....#....#.#..##.#..#.#.#..
 | 
			
		||||
..#.#....#.##...#..#.....#.#...
 | 
			
		||||
............#....#..#.......#..
 | 
			
		||||
#...#...#.#......#...##.....#.#
 | 
			
		||||
......#....#....#.......#......
 | 
			
		||||
....#.......#..........#....#..
 | 
			
		||||
........#####........#....#....
 | 
			
		||||
......#....##..............#.#.
 | 
			
		||||
....#....#.......#.......#.....
 | 
			
		||||
.##.#....##....#...............
 | 
			
		||||
#.....##........#..#.#...#.#...
 | 
			
		||||
...#......##....#..............
 | 
			
		||||
.#.....#.....#.......##....##..
 | 
			
		||||
#....#..........#.#..#.........
 | 
			
		||||
......##..........##.......#...
 | 
			
		||||
.##......##.....#.#....#......#
 | 
			
		||||
....#......................#...
 | 
			
		||||
.#...........###........#...#..
 | 
			
		||||
#.#..#..#..#...##.#....#.#..#..
 | 
			
		||||
...##...........#.#..........#.
 | 
			
		||||
......#.#..#....#....#.........
 | 
			
		||||
....#....#.#......#.........##.
 | 
			
		||||
.#..#...#...##....#...#......#.
 | 
			
		||||
#.#......#...#.#.#...........#.
 | 
			
		||||
##.....#..........##....##..##.
 | 
			
		||||
...#.#.....#..##........#......
 | 
			
		||||
..#........##........#..#......
 | 
			
		||||
.......#...............##..#...
 | 
			
		||||
.......#.#....#..###...........
 | 
			
		||||
.............#........#...#....
 | 
			
		||||
#.................#......#..#..
 | 
			
		||||
...#....#..#..............#...#
 | 
			
		||||
.............#....##....#..##..
 | 
			
		||||
#........#..........##...##...#
 | 
			
		||||
............#....#.....#.#....#
 | 
			
		||||
.....#..............##..#...#..
 | 
			
		||||
..#....#......###....#.#...##..
 | 
			
		||||
....##......#.....#....#.......
 | 
			
		||||
.....#...............#.....#...
 | 
			
		||||
.#.....#.....#..............#..
 | 
			
		||||
#................#..#..........
 | 
			
		||||
.##....#....#.....#............
 | 
			
		||||
#.####...#..#..#....#..........
 | 
			
		||||
..##........##.....##......#..#
 | 
			
		||||
......#.....#...##.........##..
 | 
			
		||||
....##..#.....#.#.........#...#
 | 
			
		||||
.....##..#....#....#.#...#..#..
 | 
			
		||||
...#............#...........#..
 | 
			
		||||
.......#.#..#.#.#..#........#.#
 | 
			
		||||
....#.#........#.#.#..#...#...#
 | 
			
		||||
..#....#....#..#......#........
 | 
			
		||||
.#...........................#.
 | 
			
		||||
.#..#....####........##......#.
 | 
			
		||||
.#.....#..#.#.................#
 | 
			
		||||
.#..#...........#...#....#...#.
 | 
			
		||||
......##..#........#..#....#...
 | 
			
		||||
..#.............#....#........#
 | 
			
		||||
#.#..........#.##.......#.#..#.
 | 
			
		||||
..#....#...#...............#...
 | 
			
		||||
..............#..........#..#..
 | 
			
		||||
..#.....#.#.....#...#...#..#...
 | 
			
		||||
.........#...###.#...#........#
 | 
			
		||||
							
								
								
									
										64
									
								
								day_3/main.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										64
									
								
								day_3/main.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,64 @@
 | 
			
		||||
#include <iostream>
 | 
			
		||||
#include <fstream>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <optional>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int calcNumOfEncounteredTrees(
 | 
			
		||||
        const std::vector<std::vector<bool>>& world,
 | 
			
		||||
        const std::pair<int, int> dimensions,
 | 
			
		||||
        std::pair<int, int> slope
 | 
			
		||||
    ) {
 | 
			
		||||
        int treeCount = 0;
 | 
			
		||||
        int x = 0;
 | 
			
		||||
 | 
			
		||||
        for (int y = 0; y < dimensions.second; y += slope.second) {
 | 
			
		||||
            if (!world[y][ x % dimensions.first]) treeCount++;
 | 
			
		||||
            x += slope.first;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return treeCount;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void part1(const std::vector<std::vector<bool>>& world, const int width, const int height) {
 | 
			
		||||
    const int RISE = 1;
 | 
			
		||||
    const int RUN = 3;
 | 
			
		||||
 | 
			
		||||
    int count = calcNumOfEncounteredTrees(world, { width, height }, { RISE, RUN });
 | 
			
		||||
    std::cout << "(P1) Number of trees: " << count << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void part2(const std::vector<std::vector<bool>>& world, const int width, const int height) {
 | 
			
		||||
    int count1 = calcNumOfEncounteredTrees(world, { width, height }, { 1, 1 });
 | 
			
		||||
    int count2 = calcNumOfEncounteredTrees(world, { width, height }, { 3, 1 });
 | 
			
		||||
    int count3 = calcNumOfEncounteredTrees(world, { width, height }, { 5, 1 });
 | 
			
		||||
    int count4 = calcNumOfEncounteredTrees(world, { width, height }, { 7, 1 });
 | 
			
		||||
    int count5 = calcNumOfEncounteredTrees(world, { width, height }, { 1, 2 });
 | 
			
		||||
 | 
			
		||||
    uint64_t product = count1 * count2 * count3 * count4 * count5;
 | 
			
		||||
    std::cout << "(P2) Product of number of trees: " << product << std::endl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int main() {
 | 
			
		||||
    std::ifstream input { "../input.txt" };
 | 
			
		||||
    std::vector<std::vector<bool>> world;
 | 
			
		||||
    std::optional<int> maybeWidth = std::nullopt;
 | 
			
		||||
    int lineCount = 0;
 | 
			
		||||
 | 
			
		||||
    std::string line;
 | 
			
		||||
    while(std::getline(input, line)) {
 | 
			
		||||
        if (!maybeWidth.has_value()) maybeWidth = { line.length() };
 | 
			
		||||
 | 
			
		||||
        std::vector<bool> row;
 | 
			
		||||
        for (char c : line) row.push_back(c == '.');
 | 
			
		||||
        world.push_back(row);
 | 
			
		||||
 | 
			
		||||
        lineCount++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    part1(world, maybeWidth.value(), lineCount);
 | 
			
		||||
    part2(world, maybeWidth.value(), lineCount);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user