Files
2025-12-08 21:08:21 +02:00

40 lines
1.1 KiB
C++

#include <algorithm>
#include <cstdint>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
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<bool> 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<int>(lengthOfALine))] = true;
password++;
}
}
}
lineCount++;
}
std::cout << password << std::endl;
}