README.org

November 28, 2025 · View on GitHub

#+title: Advent of Code 2025 solutions in Swift

[[https://swift.org][file:https://img.shields.io/badge/language-Swift-red.svg]]

Daily programming puzzles at [[https://adventofcode.com/][Advent of Code]], by [[http://was.tl/][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:

#+begin_src shell swift package --allow-writing-to-package-directory new-day #+end_src

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:

#+begin_src diff // Add each new day implementation to this array: let allChallenges: [any AdventDay] = [

  • Day00()
  • Day01(), ] #+end_src

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=:

#+begin_src shell swift run -c release AdventOfCode --benchmark 3 #+end_src

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:

#+begin_src shell swiftformat . #+end_src

  • Template

Based on Apple’s [[https://github.com/apple/swift-aoc-starter-example/][swift-aoc-starter-example]].

** Major changes from the forked template

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