Daily programming puzzles at Advent of Code, by Eric Wastl. This is a small example starter project for building Advent of Code solutions.
Based on the swift-aoc-starter-example provided by Apple
- Swift 6 (Have fun with Sendable Types)
- Swift Testing instead of XCTest
The challenges assume three files (replace 00 with the day of the challenge).
Sources/Data/day00.txt: the input data provided for the challengeSources/Day00.swift: the code to solve the challengeTests/Day00Tests.swift: any unit tests that 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. It may look like a lot to type, but if your shell is correctly set up, history and auto-completien will make this easier.
Alternatively, if you don't want to use the plugin make a copy of these files, updating 00 to the day number.
In either case, you will need to add the solution to the list of available solutions:
// Add each new day implementation to this array:
let allChallenges: [any AdventDay] = [
- Day00()
+ Day00(),
+ Day01(),
]Then implement part 1 and 2. The AdventOfCode.swift file controls which challenge
is run with swift run. Add your new type to its allChallenges array. By default
it runs the most recent challenge.
The AdventOfCode.swift file controls which day's challenge is run
with swift run. By default that runs the most recent challenge in the package.
To supply command line arguments use swift run AdventOfCode. For example:
swift run -c release AdventOfCode --benchmark 3builds the binary with full optimizations, and benchmarks the challenge for day 3.
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.
Im trying out 2 space indents, enforced by the .editorconfig` file.
I use Swiftformat so this works for me:
swiftformat .