Hey! It's good to see you. I've started this repository to implement Advent of Code challenges in Swift. I'm not trying to be competitive so don't expect any groundbreaking solutions.
If you want to use Advent of Code as a motivation to learn Swift, feel free to fork this repository an get going.
Have fun!
At its heart this project is a very simple Swift executable using ArgumentParser to provide you with a easy-to-use command-line interface.
I'm currently adding all solutions to the AdventOfSwift.swift file.
There is also a Utils.swift file. It currently contains a small helper function to get the input of a specific day. As this input is specific to each participant you'll need to provide a token.
- Log in at Advent of Code
- Open your browsers console
- Find the Cookie Storage
- Copy the value of the cookie called
session
- Store it as a environment variable called
AOC_TOKEN
- Some kind of
.env
file. I'm using oh-my-zsh built-in version - Prefix the command with
AOC_TOKEN=[Your token]
- Some kind of
Make sure you've Swift installed. Open the package folder in
your favorite terminal emulator and run swift run aoswift
.
You should get a list of all available commands. Each day has
it's own command, e.g. 01.12 is swift run aoswift first
.
Open AdventOfSwift.swift
and create a a new AsyncParsableCommand
.
struct Second: AsyncParsableCommand {
func run() async throws {
}
}
Inside run()
you can start implementing your solution.
Before you can run this command make sure to add it to
the CommandConfiguration
inside the AdventOfSwift
struct
to the array of the subcommands
parameter.
static var configuration = CommandConfiguration(
abstract: "Solutions for AoC problems",
subcommands: [
First.self,
Second.self
]
)
Now you can run swift run aoswift second
to
test your implementation.
Set the environment variable AOC_LEADERBOARD
to a
private leaderboard token.
swift run aoswift leaderboard
By default this will print the current Top 10 by their local score on the specified leaderboard.
You can customize this behavior by providing a number of results.
// Get results for the first 5 members
swift run aoswift leaderboard --number-of-results 5
// Get results for all members
swift run aoswift leaderboard --number-of-results all
[X] Leaderboard support
[] Linux Support