Solve day 1 part 1

This commit is contained in:
Reimar 2025-12-15 14:27:48 +01:00
commit f3ae7216c3
2 changed files with 35 additions and 0 deletions

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
input.txt
.idea/
day_*
!*.cpp

31
day_1.cpp Normal file
View File

@ -0,0 +1,31 @@
#include <fstream>
#include <iostream>
int main()
{
int dial = 50;
int password = 0;
std::ifstream file("input.txt");
std::string line;
while (getline(file, line)) {
int delta = std::stoi(line.substr(1));
switch (line[0]) {
case 'L':
dial -= delta;
while (dial < 0) dial += 100;
break;
case 'R':
dial = (dial + delta) % 100;
break;
}
if (dial == 0) password++;
}
std::cout << password << std::endl;
return 0;
}