#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, false); beams[currentLine.find('S')] = true; // We are counting each split not total amount of beams!! 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] == true) { beams[std::max(position - 1, 0)] = true; beams[position] = false; beams[std::min(position + 1, static_cast(lengthOfALine))] = true; password++; } } } lineCount++; } std::cout << password << std::endl; }