Skip to content

Commit 7406ded

Browse files
committed
2025 day 1: solve part 1
1 parent b3ca90f commit 7406ded

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Day 1:
2+
3

2025/input/day01/example1.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
L68
2+
L30
3+
R48
4+
L5
5+
R60
6+
L55
7+
L1
8+
L99
9+
R14
10+
L82

2025/src/day01.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/******************************************************************************
2+
* File: day01.cpp
3+
*
4+
* Author: Eric T. Johnson (yut23)
5+
* Created: 2025-12-01
6+
*****************************************************************************/
7+
8+
#include "day01.hpp"
9+
#include "lib.hpp"
10+
#include <fstream> // for ifstream
11+
#include <iostream> // for cout
12+
13+
int main(int argc, char **argv) {
14+
std::ifstream infile = aoc::parse_args(argc, argv).infile;
15+
16+
auto rotations = aoc::day01::read_input(infile);
17+
18+
int dial = 50;
19+
int part1 = 0;
20+
for (const auto rot : rotations) {
21+
dial += rot;
22+
dial %= 100;
23+
if (dial == 0) {
24+
++part1;
25+
}
26+
}
27+
28+
std::cout << part1 << "\n";
29+
30+
return 0;
31+
}

2025/src/day01.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/******************************************************************************
2+
* File: day01.hpp
3+
*
4+
* Author: Eric T. Johnson (yut23)
5+
* Created: 2025-12-01
6+
*****************************************************************************/
7+
8+
#ifndef DAY01_HPP_XFIW6CVE
9+
#define DAY01_HPP_XFIW6CVE
10+
11+
#include <iostream> // for istream
12+
#include <string> // for string, getline
13+
#include <vector> // for vector
14+
15+
namespace aoc::day01 {
16+
17+
auto read_input(std::istream &is) {
18+
// read file line-by-line
19+
std::string line;
20+
std::vector<int> rotations;
21+
while (std::getline(is, line)) {
22+
int rotation = std::atoi(line.c_str() + 1);
23+
if (line[0] == 'L') {
24+
rotation *= -1;
25+
}
26+
rotations.push_back(rotation);
27+
}
28+
return rotations;
29+
}
30+
31+
} // namespace aoc::day01
32+
33+
#endif /* end of include guard: DAY01_HPP_XFIW6CVE */

0 commit comments

Comments
 (0)