Skip to content

execreate/advent-of-code-2025

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advent of Code 2025 (Go)

Solving Advent of Code 2025 puzzles in Go with a tiny, file-driven solver and a simple CLI powered by Cobra.

This repository reads inputs from files, runs the selected day/part solver(s), and writes results back to files. It also includes structured logging via Uber Zap.

Requirements

  • Go 1.25+
  • macOS/Linux/Windows

Install / Build

  • Run from source:
    • go run .
  • Build a binary:
    • go build -o dist/app . and then run it with ./dist/app

Usage

The CLI defaults to running all available days and parts, reading from ./data/inputs and writing to ./data/outputs. For more information run go run . --help.

Examples:

  • Run everything (all days, all parts) using real inputs:

    • go run .
    • or ./dist/app if you built a binary
  • Run everything in demo mode (reads demo-input.txt, writes demo-output.txt):

    • go run . --demo
  • Run a specific day (both parts):

    • go run . --day 1 or go run . -d1
  • Run a specific day and part:

    • go run . --day 2 --part 1 or go run . -d2 -p1
  • Use custom input/output directories:

    • go run . --inputs ./my-inputs --outputs ./my-outputs
  • Enable verbose debug logs:

    • DEBUG=1 go run . --day 1 --part 2

Input and Output Layout

By default, the solver expects inputs and writes outputs in these locations:

  • Real input for day N: data/inputs/dayN/input.txt
  • Demo input for day N (when --demo): data/inputs/dayN/demo-input.txt

Outputs are written automatically, creating folders if needed:

  • Real output for day N, part P: data/outputs/dayN/partP/output.txt
  • Demo output for day N, part P (when --demo): data/outputs/dayN/partP/demo-output.txt

So make sure to create the appropriate folder structure and put your inputs in the data/inputs/dayN/ folders before running the solver.

Development

Project structure (short):

  • cmd/ — Cobra root command and flags
  • code/ — solvers, orchestrator, and I/O helpers
  • data/ — example inputs and outputs
  • utils/ — shared utilities (e.g., logger)
  • main.go — entry point that delegates to cmd/

Key files:

  • code/main.go — the Solve function routes execution to the correct solver(s) using the Solvers array.
  • code/config.go — helper functions for file I/O:
    • readPuzzleInput(day int) string
    • writePuzzleOutput(day, part int, output string)
  • utils/logger.go — configured Zap logger. Set DEBUG=1 to see debug logs (uses Zap's development logger).

Adding a new day

  1. Create solver functions in code/, following the existing pattern:

    • dayNPart1()
    • dayNPart2()

    Inside each solver you typically:

    • Read the input: input := readPuzzleInput(N)
    • Compute the result for that part
    • Persist the result: writePuzzleOutput(N, 1, result) (or 2 for part 2)
    • Optionally log with context:
      logger := utils.Logger.With(zap.Int("day", N), zap.Int("part", 1))
      logger.Debug("starting solver")
  2. Register the new day in code/main.go by extending the Solvers array in init():

    Solvers = [][]func(){
        {day1Part1, day1Part2},
        {day2Part1, day2Part2},
        {day3Part1, day3Part2}, // <-- add new day here
    }
  3. Add your input files under data/inputs/dayN/:

    • Real: input.txt
    • Demo: demo-input.txt
  4. Run your solver locally:

    • Real input: go run . --day N
    • Demo input: go run . --day N --demo

Local iteration tips

  • Use DEBUG=1 to enable verbose logs while developing.
  • Keep solvers deterministic and side-effect free except for file I/O via the provided helpers.
  • Prefer small, testable functions inside each dayN-partM files.

License

This project is released under the MIT License. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages