Skip to content

Abizern/aoc-swift-2025

Repository files navigation

Advent of Code 2025 solutions in Swift

https://img.shields.io/badge/language-Swift-red.svg

Daily programming puzzles at Advent of Code, by Eric Wastl.

Requirements

  • Swift 6.2

Set up for challenges

The challenges assume three files (replace 00 with the day of the challenge):

  • Sources/Data/day00.txt: the input data for the challenge
  • Sources/Day00.swift: the code to solve the challenge
  • Tests/Day00Tests.swift: any unit tests you want to include

The Package contains a plug-in to generate these files.

To start a new day’s challenge, cd to the root directory of the package and run:

swift package --allow-writing-to-package-directory new-day <day-number>

which will create the three files for the day. History and auto-completion will make this easier.

Alternatively, if you don’t want to use the plugin, copy these files and update 00 to the day number.

In either case, add the solution to the list of available solutions:

// Add each new day implementation to this array:
let allChallenges: [any AdventDay] = [
-  Day00()
+  Day01(),
]

Then implement part 1 and 2.

The AdventOfCode.swift file controls which challenge is run with swift run. By default it runs the most recent challenge.

To supply command-line arguments, use swift run AdventOfCode:

swift run -c release AdventOfCode --benchmark 3

This builds the binary with full optimizations and benchmarks the challenge for day 3.

Input Files

The creator of Advent of Code requests that personal input files not be added to repositories, so they must be added manually.

Add them to Sources/Data/ as DayXX.txt.

Formatting and Linting

I’m trying out 2-space indents, enforced by the .editorconfig file.

I use SwiftFormat, so:

swiftformat .

Template

Based on Apple’s swift-aoc-starter-example.

Major changes from the forked template

  • Swift 6.2 (Have fun with Sendable types)
  • Swift Testing instead of XCTest

About

Swift solutions to Advent of code 2025

Topics

Resources

License

Stars

Watchers

Forks

Languages