#include #include #include #include #include #include int main() { std::fstream input("input"); std::string currentLine = ""; uint16_t lineCount = 0, lengthOfALine = 0; uint64_t password = 0; // We are skipping the first line since it only tells us // where to start with 'S' std::getline(input, currentLine, '\n'); lengthOfALine = currentLine.length(); std::vector beams(lengthOfALine, 0); beams[currentLine.find('S')] = 1; // Each path the beam went now *sigh* while (std::getline(input, currentLine, '\n')) { // Ignore useless middle lines if (lineCount % 2 == 1) { for (int16_t position = 0; position < lengthOfALine; position++) { if (currentLine[position] == '^' && beams[position]) { // Basically idea is to pass the possible timelines to the split beams beams[std::max(position - 1, 0)] += beams[position]; beams[std::min(position + 1, static_cast(lengthOfALine))] += beams[position]; beams[position] = 0; } } } lineCount++; } // Let's see how many possible timelines were able to reach at the end for (uint64_t val : beams) { password += val; } std::cout << password << std::endl; }