• Home
  • About
    • 康青旭 - Germán Caggianese photo

      康青旭 - Germán Caggianese

      Refactoring entropy in my Mind

    • Learn More
    • Email
    • Instagram
    • Github
    • Codeberg   Codeberg
  • All Posts
  • Projects
  • Areas
  • Resources

Advent of Code 2025 - Day 1

03 Dec 2025

Reading time ~9 minutes

“Due to new security protocols, the password is locked in the safe below. Please see the attached document for the new combination.”

Github: GCaggianese/AoC-2025/D2

Puzzle Day 1 - Advent of Code

  • dial from 00 to 99 (NN), makes a click when reaching each number.
    • This means 100 possible values to wrap around.

Input Structure

  • Sequence of rotations (1 per line)

    • L → Rotation to lower numbers
    • R → Rotation to higher numbers
  • Wrap it with %, as C++ → use modular arithmetic (Gauss) with floored division convention

  • NN → number of rotations.

  • You start from 50.

Solution using C++ STD 20

  • Meson is there just because I was learning it right before AoC. You can just g++ src/main.cpp -o aoc-2020-d1 or whatever you feel like doing.
  • I actually just used org-babbel to solve it.

  • Github link: GCaggianese/AoC-2025
  • Codeberg link: GCaggianese/AoC-2025
    ...
    R31
    Dial position: 86
    R25
    Dial position: 11
    Clicks: 1129

Correct answer~! 🌟+1


int dial = 50;
int clicker = 0;

template <typename T> T floor_mod(T a, T b) {
    return a - b * std::floor(static_cast<double>(a) / static_cast<double>(b));
}

void fright(int r) { dial = floor_mod((dial + r), 100); }

void fleft(int l) { dial = floor_mod((dial - l), 100); }

void click() {
    if (dial == 0) {
        clicker += 1;
    }
}

void parse_file(std::string_view filepath) {
    std::ifstream file(filepath.data());

    for (std::string line; std::getline(file, line);) {
        if (line.empty())
            continue;

        char direction = line[0];

        int value = 0;
        auto [ptr, ec] =
            std::from_chars(line.data() + 1, line.data() + line.size(), value);

        if (ec == std::errc{}) { // Success
            std::cout << line << '\n';

            if (direction == 'L') {
                fleft(value);
                click();
                std::cout << "Dial position: " << dial << "\n";
            } else if (direction == 'R') {
                fright(value);
                click();
                std::cout << "Dial position: " << dial << "\n";
            }
        }
        if (ec != std::errc{}) { // Fail
            std::cerr << "Parse error on line: " << line << '\n';
            continue;
        }
    }
}

int main(){

    std::cout << "Hey AoC 2025!\n\n";
    parse_file("input_test.txt");
    std::cout << "Clicks: " << clicker << "\n";

    return 0;
}

Unless stated otherwise, the content of the website is licensed under a Creative Commons Attribution 4.0 International license.

© 2025 Germán Caggianese(康青旭)