Day7 Question 1

This commit is contained in:
2025-12-08 21:08:21 +02:00
parent 0cd5ec7826
commit f13d80dd30
3 changed files with 197 additions and 0 deletions

39
Day7/Question1/main.cpp Normal file
View File

@@ -0,0 +1,39 @@
#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;
}