mirror of
https://github.com/szymon-jozef/advent_of_code_2025.git
synced 2026-09-07 12:10:41 +02:00
first challenge
This commit is contained in:
4570
1/input.txt
Normal file
4570
1/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
41
1/main.cpp
Normal file
41
1/main.cpp
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#include <fstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int translate_movement(string input) {
|
||||||
|
string symbol = input.substr(0, 1);
|
||||||
|
int ammount = stoi(input.substr(1));
|
||||||
|
return (symbol == "R") ? ammount : -ammount;
|
||||||
|
}
|
||||||
|
|
||||||
|
int normalize_number(int number) {
|
||||||
|
number %= 100;
|
||||||
|
if (number < 0)
|
||||||
|
number += 100;
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::ifstream file("input.txt");
|
||||||
|
|
||||||
|
vector<string> data;
|
||||||
|
string s;
|
||||||
|
|
||||||
|
while (file >> s) {
|
||||||
|
data.push_back(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
int count_zero = 0;
|
||||||
|
int pos = 50;
|
||||||
|
for (const string &movement : data) {
|
||||||
|
int delta = translate_movement(movement);
|
||||||
|
pos = normalize_number(pos + delta);
|
||||||
|
|
||||||
|
if (pos == 0) {
|
||||||
|
count_zero++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Dial pointed at zero %d times.", count_zero);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user