~cdv/aoc-2023

Advent of Code 2023 solutions

refs

main
browse  log 

clone

read-only
https://git.sr.ht/~cdv/aoc-2023
read/write
git@git.sr.ht:~cdv/aoc-2023

You can also use your local clone with git send-email.

#Advent of Code 2023 Solutions

Advent of Code is back again. And once again I'm trying to solve it.

Here you'll find solutions to the puzzles in the following languages:

More to come, maybe.

#Note On Automation

I belive my tools adhere to the Advent of Code automation guidelines.

  • The only endpoints I hit are the inputs https://adventofcode.com/$YEAR/day/$DAY/input.
  • If an input already exists at inputs/day_$DAY.txt no requests are issued,
    • unless a user has explicitly requests a refresh via the documented commandline options below.
  • The User-Agent is set to git.sr.ht/~cdv/aoc-2023 (<relative path to file/module issuing the requests> ; <library used>/<version>) by chris@vittal.dev
    • for example, the runner script for my rust solutions x.py, sets the user agent to: git.sr.ht/~cdv/aoc-2023 (rs/x.py ; requests/2.28.1) by chris@vittal.dev

#Details

Each implementation has a few quirks. I try to document them below, as well as provide instructions on how to build/run every solution.

#Rust

This uses nightly rust for certain const generic functions.

Every solution is it's own binary day01 to day25 that takes inputs on standard input and writes both parts to standard output.

#To Run
cargo run --bin "day13" < input/day_13.txt

There is also a convenience script x.py that will download input and run solutions.

It is configured with an aoc.toml file:

# aoc.toml for configuring x.py helper
year = 2023
session = 'session token'
input_dir = '../input'

To use the x.py script:

$ ./x.py -h
usage: x.py [-h] [--refresh] [--all] [--config CONFIG] [--debug]
            [--verbose | --quiet]
            [day ...]

Advent of Code helper for rust solutions

positional arguments:
  day                   days to run

optional arguments:
  -h, --help            show this help message and exit
  --refresh, -r         force a refresh of the puzzle input
  --all, -a             run all days
  --config CONFIG, -C CONFIG
                        TOML config file to use
  --debug               build/run solutions in debug mode
  --verbose, -v         increase messaging
  --quiet, -q           reduce messaging

#C

Built with the meson build system. Tested on macOS and Linux, may work elsewhere, especially on other POSIX systems. There is also a binary (aocc in c/util/run.c), that can build the binaries, download the inputs, and run the solutions. It depends on libcurl and jansson.

#To Build
meson setup build --buildtype=release
ninja -C build
#To Run
#Standalone
build/day13 < input/day_13.txt
#With aocc
build/aocc 13
#More on aocc

aocc accepts the following command line flags and arguments.

aocc [-rav] [-c <config]] [-C <dir>] <days>...

-r          Always download new input
-a          Run all days (will not run future days)
-v          Print more information
-c <config> Use config rather than 'aoc.json'
-C <dir>    Change to directory 'dir' before executing
<days>...   If -a was not specified, run all days

It's config file, aoc.json should have the following fields

{
  "year": 2021,
  "session": "your session cookie string",
  "input_dir": "where your inputs live",
  "build_dir": "where the project build directory is, ususally build"
}

#Python

The python solutions are all contained in an aoc module. It use requests to download necessary inputs and toml for configuration.

#To Run
python -m aoc -h
usage: __main__.py [-h] [--refresh] [--all] [--stdin] [day ...]

positional arguments:
  day         days to run

optional arguments:
  -h, --help  show this help message and exit
  --refresh   force a refresh of the puzzle input
  --all, -a   run all days
  --stdin     read input from stdin, (only if only one day specified)

Of note is the --stdin option, if only one day is specified (no days defaults to today), then the input can be passed on standard input.

# aoc.toml for configuring python solutions
year = 2023
session = 'session token'
input_dir = '../input'