You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
1.1 KiB
42 lines
1.1 KiB
#include <vector>
|
|
#include <utility>
|
|
#include <array>
|
|
|
|
#include "solutions.hpp"
|
|
|
|
using namespace std;
|
|
|
|
pair<string, string> solve3(istream& input) {
|
|
vector<string> my_map;
|
|
uint64_t width;
|
|
bool width_set = false;
|
|
for (string line; getline(input, line); ) {
|
|
my_map.push_back(line);
|
|
if (!width_set) {
|
|
width = line.length();
|
|
width_set = true;
|
|
}
|
|
}
|
|
array<pair<uint64_t, uint64_t>, 5> slopes { {
|
|
{1, 1},
|
|
{3, 1},
|
|
{5, 1},
|
|
{7, 1},
|
|
{1, 2}
|
|
} };
|
|
uint64_t product = 1;
|
|
uint64_t part1;
|
|
for (auto slope : slopes) {
|
|
uint64_t total_trees = 0;
|
|
for (auto pos = pair(0, 0); pos.second < my_map.size(); ) {
|
|
total_trees += (int) my_map[pos.second][pos.first] == '#';
|
|
pos.first = (pos.first + slope.first) % width;
|
|
pos.second += slope.second;
|
|
}
|
|
product *= total_trees;
|
|
if (slope.first == 3 && slope.second == 1) {
|
|
part1 = total_trees;
|
|
}
|
|
}
|
|
return pair(to_string(part1), to_string(product));
|
|
}
|