-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
35 lines (31 loc) · 970 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "file.h"
#include <iostream>
#include <vector>
namespace aoc2015_day01 {
int part_1(std::string_view path) {
std::string input = file::readFileAsString(path);
int sol = 0;
for (const auto& l : input) {
sol += 1 * (l == '(') + (-1) * (l == ')');
}
return sol;
}
int part_2(std::string_view path, int basement = -1) {
std::string input = file::readFileAsString(path);
int currentFloor = 0;
for (int i = 0; i < input.size(); ++i) {
currentFloor += 1 * (input[i] == '(') + (-1) * (input[i] == ')');
if (currentFloor == basement) {
return i + 1;
}
}
return 0;
}
}
#ifndef TESTING
int main() {
std::cout << "Part 1: " << aoc2015_day01::part_1("../2015/day01/input.in") << std::endl;
std::cout << "Part 2: " << aoc2015_day01::part_2("../2015/day01/input.in") << std::endl;
return 0;
}
#endif