Solve day 1 part 1
This commit is contained in:
commit
f3ae7216c3
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
input.txt
|
||||||
|
.idea/
|
||||||
|
day_*
|
||||||
|
!*.cpp
|
||||||
31
day_1.cpp
Normal file
31
day_1.cpp
Normal 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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user