Added 2025 day 1.

This commit is contained in:
David Vereb
2025-12-01 10:34:29 -05:00
parent ddcf072281
commit f0956f1f15
4 changed files with 4859 additions and 0 deletions

2
2025/1/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++20 main.cpp

4780
2025/1/data.txt Normal file

File diff suppressed because it is too large Load Diff

10
2025/1/data_test.txt Normal file
View File

@@ -0,0 +1,10 @@
L68
L30
R48
L5
R60
L55
L1
L99
R14
L82

67
2025/1/main.cpp Normal file
View File

@@ -0,0 +1,67 @@
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> input;
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
std::string line;
while(!ifs.eof())
{
ifs >> line;
if(ifs.eof())
break;
input.push_back(line);
}
int answer = 0;
int num = 50;
for(const std::string &line : input)
{
bool to_right = ('R' == line[0]);
int amount = std::atoi(line.substr(1).c_str());
if(!to_right)
amount *= -1;
num += amount;
num %= 100;
if(num == 0)
++answer;
}
std::cout << "Part 1: " << answer << std::endl;
answer = 0;
num = 50;
for(const std::string &line : input)
{
bool to_right = ('R' == line[0]);
int amount = std::atoi(line.substr(1).c_str());
// slow, but accurate. :)
for(auto i = 0; i < amount; ++i)
{
num += (to_right ? 1 : -1);
num %= 100;
if(num < 0)
num += 100;
if(num == 0)
++answer;
}
}
std::cout << "Part 2: " << answer << std::endl;
return 0;
}