#include #include #include "cached_shortest_sequences.h" #include "segmented_sequences.h" #include "keypad_funcs.h" #include "convert_code.h" #include "input.h" int main(int argc, char **argv) { std::string input_text = ReadFile(argv[1]); Lines lines(input_text); CachedShortestSequences cached_shortest_sequences; std::vector codes; for (;;) { auto line = lines.Next(); if (!line || line->empty()) { break; } codes.emplace_back(line->data(), line->size()); } std::vector buffer; size_t total = 0; for (const auto &code : codes) { size_t converted_code = ConvertCode(code); auto shortest_sequences0 = cached_shortest_sequences.Find(code, ApplyNumericCommand); for (size_t layer = 0; layer < 25; ++layer) { auto shortest_sequences1 = cached_shortest_sequences.Find( shortest_sequences0, ApplyDirectionalCommand); shortest_sequences0 = shortest_sequences1; } total += shortest_sequences0->MinSize() * converted_code; } std::cout << total << std::endl; return 0; }