Simplify part 1

master
Nick Krichevsky 2020-12-10 04:29:46 -05:00
parent 2adbdf08ce
commit bf9ef67cbe
1 changed files with 1 additions and 10 deletions

View File

@ -49,15 +49,6 @@ void prepareInput(std::vector<int> &input) {
std::sort(input.begin(), input.end()); std::sort(input.begin(), input.end());
} }
template <typename Key, typename Value>
Value getOrDefault(const std::map<Key, Value> &map, Key key, Value defaultValue) {
try {
return map.at(key);
} catch (std::out_of_range) {
return defaultValue;
}
}
/** /**
* Finds the number of paths from the given source node to the target (the end of the adapters lsit) * Finds the number of paths from the given source node to the target (the end of the adapters lsit)
* Based on algorithm from: * Based on algorithm from:
@ -101,7 +92,7 @@ int part1(const std::vector<int> &input) {
differenceCounts[difference]++; differenceCounts[difference]++;
} }
return getOrDefault(differenceCounts, 1, 0) * getOrDefault(differenceCounts, 3, 0); return differenceCounts[1] * differenceCounts[3];
} }
long part2(const std::vector<int> &input) { long part2(const std::vector<int> &input) {