Initial commit
This commit is contained in:
32
2020/puzzle-10-01.cc
Normal file
32
2020/puzzle-10-01.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
|
||||
using Jolt = unsigned long;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::vector<Jolt> jolts;
|
||||
for (std::string line; std::getline(std::cin, line);) {
|
||||
jolts.push_back(std::stoul(line));
|
||||
}
|
||||
|
||||
std::sort(jolts.begin(), jolts.end());
|
||||
std::array<unsigned, 4> gaps = {};
|
||||
|
||||
Jolt last = 0;
|
||||
for (auto j : jolts) {
|
||||
++gaps[j - last];
|
||||
last = j;
|
||||
}
|
||||
// and the gap to our voltage
|
||||
++gaps[3];
|
||||
|
||||
std::cout << gaps[1] << " * " << gaps[3] << " = " << gaps[1] * gaps[3]
|
||||
<< "\n";
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user