#include #include #include #include #include #include #include #include "solutions.hpp" using namespace std; typedef std::pair(*solution_t)(std::istream&); template void init_solutions(std::array &solutions); template pair solve(istream&) { stringstream s; s << "solution " << N << " not implemented"; throw logic_error(s.str()); } template constexpr void do_init(solution_t *solutions) { solutions[I-1] = solve; do_init(solutions); } template <> constexpr void do_init<1>(solution_t *solutions) { solutions[0] = solve<1>; } template void init_solutions(array &solutions) { do_init(solutions.data()); } int main(int argc, char *argv[]) { array(*)(istream&), 25> solutions; init_solutions(solutions); if (argc < 2) { return 0; } int problem_number = stoi(string(argv[1])); try { auto x = solutions.at(problem_number-1); auto answer = x(cin); cout << "Solution 1: " << answer.first << endl; cout << "Solution 2: " << answer.second << endl; } catch (exception const &e) { cerr << "error: " << e.what() << endl; } return 0; } //istream get_input() { // CURL *curl; // CURLcode res; // // char url[44] = {0}; // sprintf(url, "https://adventofcode.com/2020/day/%d/input"); // // curl_global_init(CURL_GLOBAL_ALL); // curl = curl_easy_init(); // curl_easy_setopt(curl, CURLOPT_URL, "https://adventofcode.com/2020/day/1/input"); // curl_easy_setopt(curl, CURLOPT_URL, "https://adventofcode.com/2020/day/1/input"); // // curl_global_cleanup(); //} // TODO: automatically download input files and stuff // char *home_dir = getenv("HOME"); // if (home_dir != NULL) { // // }