Completed day 3
This commit is contained in:
parent
74f6c3970b
commit
b2027635c2
3 changed files with 394 additions and 0 deletions
|
@ -4,6 +4,9 @@ day1.out: out/types.o day1.cpp day1.input
|
|||
day2.out: out/types.o day2.cpp day2.input
|
||||
g++ $(flags) day2.cpp out/types.o -o $@
|
||||
|
||||
day3.out: out/types.o day3.cpp day3.input
|
||||
g++ $(flags) day3.cpp out/types.o -o $@
|
||||
|
||||
out/types.o: types.hpp types.cpp
|
||||
mkdir -p out/
|
||||
g++ $(flags) -c types.cpp -o $@
|
||||
|
|
68
2020/day3.cpp
Normal file
68
2020/day3.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*******************************************************************************
|
||||
*
|
||||
* Copyright (c) 2020 Gnarwhal
|
||||
*
|
||||
* -----------------------------------------------------------------------------
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files(the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "types.hpp"
|
||||
|
||||
auto read_field_and_count_trees(std::vector<std::string> & trees, usize horizontal_increment, usize vertical_increment) -> u64 {
|
||||
auto tree_count = u64(0);
|
||||
|
||||
auto x_index = usize(-horizontal_increment);
|
||||
auto y_index = usize(-1);
|
||||
auto line = std::string();
|
||||
auto file = std::ifstream("day3.input");
|
||||
|
||||
while (getline(file, line)) {
|
||||
auto vertical_check = (++y_index % vertical_increment == 0);
|
||||
tree_count += vertical_check * (line[(x_index += (vertical_check * horizontal_increment)) % line.size()] == '#');
|
||||
}
|
||||
|
||||
return tree_count;
|
||||
}
|
||||
|
||||
auto main(i32 argc, char ** argv) -> i32 {
|
||||
auto trees = std::vector<std::string>();
|
||||
auto tree_counts = std::vector<u64>();
|
||||
|
||||
tree_counts.push_back(read_field_and_count_trees(trees, 3, 1));
|
||||
std::cout << tree_counts[0] << std::endl;
|
||||
|
||||
tree_counts.push_back(read_field_and_count_trees(trees, 1, 1));
|
||||
tree_counts.push_back(read_field_and_count_trees(trees, 5, 1));
|
||||
tree_counts.push_back(read_field_and_count_trees(trees, 7, 1));
|
||||
tree_counts.push_back(read_field_and_count_trees(trees, 1, 2));
|
||||
auto tree_count_product = u64(1);
|
||||
for (auto tree_count : tree_counts) {
|
||||
tree_count_product *= tree_count;
|
||||
}
|
||||
std::cout << tree_count_product << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
323
2020/day3.input
Normal file
323
2020/day3.input
Normal file
|
@ -0,0 +1,323 @@
|
|||
.....#............#....#####.##
|
||||
.#.#....#......#....##.........
|
||||
......#.#.#.....###.#.#........
|
||||
......#...#.....#####....#..##.
|
||||
...#............##...###.##....
|
||||
#.....#...#....#......##....##.
|
||||
#...#.#....#..#..##.##...#.....
|
||||
.......#..........#..#..#.#....
|
||||
.#.....#.#.......#..#...#....#.
|
||||
#..#.##.#..................###.
|
||||
...#.#.##...##.###.....#..#...#
|
||||
..#.#...#............#.......#.
|
||||
#..#.#..#.#....#...#.#.....#..#
|
||||
#......##....#..#.#.#........#.
|
||||
....#..#.#.#.##............#..#
|
||||
....#..#..#...#.#.##......#...#
|
||||
##...#...........#.....###.#...
|
||||
..#...#.#...#.#.....#....##.##.
|
||||
....##...##.#....#.....#.##....
|
||||
#........##......#......#.#.#.#
|
||||
....#.#.#.........##......#....
|
||||
.#......#...#.....##..#....#..#
|
||||
....#..#.#.....#..........#..#.
|
||||
..##...#..##................#.#
|
||||
.....#....#.#..#......#........
|
||||
........#..#.#......#.#........
|
||||
.....#.#....##.###....#...#....
|
||||
...##.#.......#....###..#......
|
||||
............##.#..#...#........
|
||||
#..###..#.....#.####...........
|
||||
.......##.....#......#......#..
|
||||
#........##..#.....##.......#.#
|
||||
#.##...#...#...#......##..#.#.#
|
||||
......#....##.#.#...#...##....#
|
||||
#..#....##.#......#.......##...
|
||||
.#..........#..........#....#.#
|
||||
#.....##......##....#..........
|
||||
..#.#.....#.#...#........#.....
|
||||
...#........#..#..#.##..##.....
|
||||
......###.....#..#...#.###...##
|
||||
.##.##.......#.......###...#...
|
||||
#.#..#.#.#....#.....###..#...##
|
||||
......#.##..........#.......##.
|
||||
#..#.#.........#.....##...##...
|
||||
..#...#....#....###.#......#...
|
||||
.....#..#.######.....#..#.#....
|
||||
..#.#.....#.....##.#....##.#.##
|
||||
...#.#.#....#....##..#..#.#.##.
|
||||
...........#.#...#..#..####....
|
||||
.........#####.#.#.#...#.##.#..
|
||||
.......#...#......#.##.#.##....
|
||||
....#.....#.....###..........#.
|
||||
.#.###....##.#..#..........#...
|
||||
#...#.........##.....####....#.
|
||||
##....##...#..........#........
|
||||
...#.#.#.#....#..........#.....
|
||||
.......#....#......##.......#..
|
||||
.#.#..#.........#.#.##....#....
|
||||
..#.............#..##.#.##..###
|
||||
.#.##..............#..#..##..#.
|
||||
..##.#..#......#...##..#.##...#
|
||||
......#..#....#....#....##..#..
|
||||
...#...##.............#..###...
|
||||
...##....#.#.##........#.....##
|
||||
....#.#.......#..###..#....####
|
||||
#...#...##..#.####..#...##....#
|
||||
.......#..#.##..#...#.#........
|
||||
###.#......#..##..#......#.##..
|
||||
#....#............#.....#......
|
||||
..##...#..##......#..#....#....
|
||||
.#..##...#....#.#...#...#..#..#
|
||||
........#....###...#..##..###.#
|
||||
.........#....#....#..#.#.#...#
|
||||
.#....###.##...#.#...........##
|
||||
..#..#.#..#.#.##..#...##.......
|
||||
##..#.#.#....#...#..#..........
|
||||
#..#.......#....#..##...####...
|
||||
............#.#..........##.##.
|
||||
#...#..#.#....#..#.#....##.....
|
||||
......#...#...#.##............#
|
||||
#.....##..###..#.#..#.#.##..#.#
|
||||
#..#.#..#......#.......##.#....
|
||||
##..#.#..#...#......#.##...###.
|
||||
.#....#..............#....#.#..
|
||||
..#.#..##....#....#..##........
|
||||
.#.#...#..#.....#.#..##........
|
||||
.....#..#.#......#....#.#..#.#.
|
||||
....#.###...###.#.#.....#......
|
||||
...........#.#....##....##.....
|
||||
..#..#.##..........#...#...#..#
|
||||
.....#.###.#..........#........
|
||||
....#....##........###...#.....
|
||||
.#.....##.......#....#..##..###
|
||||
#.....#...............##......#
|
||||
#..#.#..#.#.#.....#.#...#......
|
||||
.##.###...#....#..........##...
|
||||
.#.......#.....................
|
||||
.#.#....#...##..#...#...##.....
|
||||
.#.#...#.......#.......#...#...
|
||||
....#.#..#.#..#...#....##......
|
||||
....##.....#.##....#.##..##..##
|
||||
..#............#...###.##..#...
|
||||
.#..#.........#.##....#....#..#
|
||||
.#..##..#..#........#.#.##.#.##
|
||||
.###.#...#...............#...#.
|
||||
...#.##.##.#......#...#....##.#
|
||||
#......##.......##...###....#.#
|
||||
#..##.....##......#.#.##....#.#
|
||||
...#.#....#.#.#...........##..#
|
||||
#.....##......##.#..........##.
|
||||
###....#.#...#.#..####.........
|
||||
.##.#.#...##..#.....#..#...#...
|
||||
#.....#.#......#..........#.#..
|
||||
..###.##.#...................#.
|
||||
#.............#..#........#.##.
|
||||
#.#.#.#..#.....##..##.#....#...
|
||||
...#...#..#...#..##..##........
|
||||
...##...##..#...##...........#.
|
||||
.####..#.#.#.##.#.......#......
|
||||
...#....#.......#......#.......
|
||||
.....#.#...#...#..##..#..#.....
|
||||
......#.....###.#..#..#.#..###.
|
||||
.#....#....#..#..##.....##...#.
|
||||
.#.............##.###.#...#.#..
|
||||
#..#..#......#.###............#
|
||||
##.#..##....#..........#.#.#...
|
||||
......#........#...#.......##..
|
||||
....#.#..#..........#.....#.#..
|
||||
...#..#...#.#...#........#.....
|
||||
.....##...#....#.........##.##.
|
||||
....#...#...#.##.##...#....#...
|
||||
.#..#.....##......#..#.#..#....
|
||||
........##...##.##......#.#.#.#
|
||||
.................#..#.....##.#.
|
||||
...#.....#...#.........#..#.#.#
|
||||
....##.#.....#........#...#..#.
|
||||
#...............#..#.....#...#.
|
||||
.....#..#....#...#.####.#.#....
|
||||
####.#..#.##...#....#...##.....
|
||||
#...##..#...####..#....#.#...#.
|
||||
..#.......#.##..##...#.#.......
|
||||
...........##.......#....#..#..
|
||||
#.##....#...#.....#....##......
|
||||
....##.#.......#..#...##.......
|
||||
...#.........##.#..#......#.###
|
||||
.#..#..#....#.#.##....###..###.
|
||||
....#.#........##........##....
|
||||
....########....#.#.#.###.#...#
|
||||
...#.###.###.##......##.......#
|
||||
.#...#.###.......#..........#..
|
||||
..#..##.........#............#.
|
||||
.......##.#...#...##...#...#..#
|
||||
#.##....#.#...#.....#..#.#.....
|
||||
..#........#..#.#.#.#....#.##..
|
||||
...#...#.#.........#...#.#..##.
|
||||
#....#......#.#...........#..##
|
||||
...#.#.#..#...##...#...#...#...
|
||||
###..........#.#..........#....
|
||||
..#....#.#.#.#............#.#..
|
||||
....#...#..###...#.#....#......
|
||||
#...........####......##.#.....
|
||||
..#..##.#...#.....#..#.......##
|
||||
#.....#..###.....#...##..##....
|
||||
##..###..##...........#.#...#..
|
||||
.....#......#..............#...
|
||||
#..#.##.###.......#.......#...#
|
||||
#........#....##......#.#......
|
||||
.#.#.#...#.......#........#.##.
|
||||
#..#..##.....#...#.#.#.#..###..
|
||||
.#.#....#..#..#.#....##.#.#....
|
||||
..#.#.........####.#...#.#.###.
|
||||
....##........##....#........#.
|
||||
................#..........#...
|
||||
..#...................###.##..#
|
||||
.........#..#..#.#...#....#.#.#
|
||||
......#.....###.....#.#..#...#.
|
||||
.#.#.....#..##............##...
|
||||
...##......##.#....#...........
|
||||
...##..##..###.#...##..........
|
||||
....###...#..#.#......#......#.
|
||||
....##..............#..#..#.#..
|
||||
####.......#...##.##..#.#......
|
||||
.#......#.....#....###..#....#.
|
||||
.#.......#...##...#..##.#......
|
||||
#.......#.......#.#....#.#.#..#
|
||||
........#..#..#............##.#
|
||||
#.#...#.#..##..#.......##..#...
|
||||
...#....#...#..........##..#...
|
||||
#.#...#.##....###......##....#.
|
||||
#..#...###........#..#....#..#.
|
||||
#....#....###....#..#.......#..
|
||||
....#.#........#.............#.
|
||||
.#.##........##...#...#...#...#
|
||||
#.....##.....#.......#.#.#.....
|
||||
.#.##..........##..#....#......
|
||||
.#..##.##.#...##....#.#....##..
|
||||
........#.#.##.#....#.#..#....#
|
||||
..#...........................#
|
||||
.#...........#....#....#.#..#..
|
||||
........##...........#...#...#.
|
||||
..#.....#..#......#..##.......#
|
||||
..#....###..###...#.#.#..#....#
|
||||
#..#.#...#......##......#......
|
||||
...........#...##..##....##....
|
||||
#.#......###..#.....#.......#.#
|
||||
#.....#....#....#.#...#...#....
|
||||
....#...#.......#....##.#..#...
|
||||
.####..##......##.#........#..#
|
||||
..###..#.#.....#...........##..
|
||||
..##.#.#..#....#..#..#.........
|
||||
..........#.#.#####...#........
|
||||
.###......##.#....#........#...
|
||||
.....#..#..#.#..#.........#....
|
||||
..#....#...#...#...##..........
|
||||
....#..##.#.........##.#..##...
|
||||
##.####..#...#.#...#.....#..###
|
||||
..#..#...#...#.....##....#..#.#
|
||||
#..##..#.....#....#.#.....##..#
|
||||
...#...........##.....#......#.
|
||||
......#...#.....#.#..###.......
|
||||
.........#.....###.##..#...#...
|
||||
.#...#.##...#..........#.#..##.
|
||||
......#.......##.....#.....##..
|
||||
........###..........#...#.....
|
||||
##.......###..###...##...#.....
|
||||
#.#.............#..#..#.#......
|
||||
..##........#.###.....#....##..
|
||||
......#...#......#....##......#
|
||||
..#.....#...##...#.......#..#..
|
||||
..#.###..##.##...#....#...##.#.
|
||||
........##...#..#.#..##.....#.#
|
||||
.......................#......#
|
||||
..##.###......#.#.............#
|
||||
....#...........###............
|
||||
##...##.....#.......##.......#.
|
||||
...#..##..##..#.#.###..#......#
|
||||
........#........#.#..#..#.....
|
||||
.#......#....##..........#...#.
|
||||
.##...........##....#..........
|
||||
.#..#....###.......#....#..##..
|
||||
.....###..........#....#.#.#...
|
||||
...#....###.#.#......#......#..
|
||||
#.#.##.#.....#..#........#...#.
|
||||
...#.##.........#..#.....#.....
|
||||
.##...##......##...###...#.....
|
||||
...#.....#.##..#...#..#........
|
||||
........#............#.#.#..##.
|
||||
###...#.....#...#..#........##.
|
||||
##...#..#.....#.#....#.#.#.....
|
||||
#..##.......#...#.#...##..#....
|
||||
#...#.##.....#.#..#.##......#.#
|
||||
..#......#.#.#.##.##..........#
|
||||
..#.##......#.#.#..##..........
|
||||
....#..#....#..#..............#
|
||||
..........###.....##..#........
|
||||
...#.....##.....#..#.#..#...##.
|
||||
.#..##.#..#....#.#......#.##...
|
||||
...#.....#..#.#...#..#.....#.#.
|
||||
#...#.#......##...#..#...#....#
|
||||
..#.......##...#..#.......#...#
|
||||
#.....#...........##.#.........
|
||||
.#......##.....####...#.......#
|
||||
........#..#.....#.......#..#..
|
||||
....#.#...##..##...#..#....#...
|
||||
#.#......#...#.#.###.....#.....
|
||||
..##...#.#........#.##....#.#.#
|
||||
.#....#......#.#...###.#.......
|
||||
.......#.#...##....#.#....#....
|
||||
.....##..##...#..#.#.....##..#.
|
||||
.##..#.#.#....##.#...#.....#...
|
||||
.#..#..##....#.##.......#...#..
|
||||
....#.##...#..##......#.....#..
|
||||
.#..#....##....#...............
|
||||
..##...#.....###...............
|
||||
..............#.#.##........#.#
|
||||
.#.#....#....#...#.#........#..
|
||||
.##...#...#.#....#....#.#.....#
|
||||
#..............#......#.####.#.
|
||||
......#...........#..#.....##..
|
||||
#.#..##.##.....#......#..#.#..#
|
||||
##.##..#.##.#.............#...#
|
||||
...#..#......#....#............
|
||||
........###.#.#..#...#.....#.##
|
||||
..#.......#.##.........#..#....
|
||||
...##.#........##...#.#.##..#..
|
||||
...#..#......#...#....#........
|
||||
...........#..#..#...##...#....
|
||||
...#.....#....#..####..##.....#
|
||||
.......#..#..#......#.........#
|
||||
#......#........###.....##....#
|
||||
..#..#..#.#.#....##...##......#
|
||||
#.#..#..###.#..#.....####......
|
||||
.#................#####....#...
|
||||
.#.........#...#.......#......#
|
||||
..#.......#######........#.....
|
||||
..#........#.....#..#...#..#..#
|
||||
.#..#.#..#....#.#..##...#..#.#.
|
||||
..#...........#.#...#.#.##.....
|
||||
...#.#.#....##.###....#...####.
|
||||
.....#..#.....#..#.#.........#.
|
||||
......##...#...###............#
|
||||
..#.#......###..####..#......#.
|
||||
###.##.#..#......##.#..##.....#
|
||||
....###...##............#.#....
|
||||
..#.....##...#...##....#...#...
|
||||
#.....#.....#...#...#.#..#.....
|
||||
####..........##.#.#..#.....##.
|
||||
...#..........#...#...##..##.#.
|
||||
..........#.........#.#..#..#..
|
||||
#....###.....#.#...#.......##.#
|
||||
#..#.##.....#..........#...#...
|
||||
...#.#.###.......##..#.....#...
|
||||
#...#.#..#.............#..#.#..
|
||||
#........#.................#..#
|
||||
..#.#....#.#..##.#...#..#....#.
|
||||
#...#..........#...###....#...#
|
||||
......#.............#....#....#
|
||||
#.#.......##.......#.#....##..#
|
||||
##...#....#.............#..#...
|
||||
........#...###.##.#..###.#...#
|
||||
...##...#..#..#...##..##......#
|
||||
..#.......##....#.#.##....#....
|
||||
.....#....#..#.#...##.#.#.....#
|
Loading…
Reference in a new issue