Day 1
This commit is contained in:
43
src/main.cpp
Normal file
43
src/main.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "fmt/base.h"
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
int main() {
|
||||
std::vector<std::string> rotations;
|
||||
int currentPos { 50 };
|
||||
int zeroCount { 0 };
|
||||
|
||||
// Step 1: Read file
|
||||
std::ifstream file("src/rotations.txt");
|
||||
std::string line;
|
||||
|
||||
if (!file) {
|
||||
fmt::print("Sex");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (std::getline(file, line)) {
|
||||
rotations.push_back(line);
|
||||
}
|
||||
|
||||
for (const auto& rotation : rotations) {
|
||||
char direction = rotation[0];
|
||||
int distance = std::stoi(rotation.substr(1));
|
||||
|
||||
if (direction == 'L') {
|
||||
currentPos = (currentPos - distance + 100) % 100;
|
||||
} else {
|
||||
currentPos = (currentPos + distance) % 100;
|
||||
}
|
||||
|
||||
if (currentPos == 0) {
|
||||
zeroCount++;
|
||||
}
|
||||
}
|
||||
|
||||
fmt::print("{}\n", zeroCount);
|
||||
}
|
||||
4510
src/rotations.txt
Normal file
4510
src/rotations.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user