Daily programming puzzles at Advent of Code, by Eric Wastl.
- Swift 6.2
The challenges assume three files (replace 00 with the day of the challenge):
Sources/Data/day00.txt: the input data for the challengeSources/Day00.swift: the code to solve the challengeTests/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 3This builds 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.
I’m trying out 2-space indents, enforced by the .editorconfig file.
I use SwiftFormat, so:
swiftformat .Based on Apple’s swift-aoc-starter-example.
- Swift 6.2 (Have fun with Sendable types)
- Swift Testing instead of XCTest