~cdv/aoc-2021

Polyglot solutions to Advent of Code 2021
solve day 23 by hand

refs

main
browse  log 

clone

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

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

#Advent of Code 2021 Polyglot Solutions

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

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

More to come, maybe.

#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

I've been using nightly rust, but don't tend to use many nightly features.

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 (identical to the python one later)
year = 2021
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

Tested with both clang 11 and gcc 10.2, built with meson version 0.56.0 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 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"
}

#Haskell

I'm using ghc 9.0.1 and cabal-install 3.6.2.0 to build the haskell solutions. The output is one aoc2021 binary that reads and runs every solution.

#Build and Run
cabal build :aoc2021
cabal run :aoc2021 -- 13

The full set of options is:

Help Options:
  -h, --help
    Show option summary.
  --help-all
    Show all help options.

Application Options:
  -a, --all :: bool
    Run all days, not just today
    default: false
  -r, --refresh :: bool
    Always refresh inputs
    default: false
  -c, --config :: text
    Path to the config file to use
    default: "aoc.json"

aoc2021 is configured via an aoc.json much like the C solutions, however only the following three fields need be present.

{
  "year": 2021
  "session": "your session cookie string",
  "input_dir": "where your inputs live"
}

#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 = 2021
session = 'session token'
input_dir = '../input'

#Golang

I've been using go 1.17. To build, just run make. The output aoc2021 accepts the following options:

usage: aoc2021 [-arh] [-i <input>] [-c <config>] [-C <dir>] <days>...

	-h           display this help
	-a           run all days (that have been released)
	-c <config>  use <config> for config file (default aoc.json)
	-C <dir>     change to <dir> before doing any other work
	-i <path>    use <path> for input if only one day specified, '-' indicates stdin
	<days>...    run specified days (unless -a is set)

The aoc.json configuration is identical to the haskell one.

{
  "year": 2021,
  "session": "your session cookie string",
  "input_dir": "where your inputs live"
}

#Ruby

Ruby 3.0.3. bin/aoc is the invoke script, solutions live in lib/adventofcode/. Usage:

Usage: aoc [options] <days>...
    -r, --refresh                    Refresh inputs before running
    -a, --all                        Run all (availible) days
    -c, --config=PATH                Use PATH for config (default 'aoc.json')
    -h, --help                       Show this help

The aoc.json configuration is identical to the haskell one.

{
  "year": 2021,
  "session": "your session cookie string",
  "input_dir": "where your inputs live"
}