~cdv/aoc-2020

Polygolot solutions to advent of code 2020
rs: avoid panic in day 20 (debug mode only, release is fine)
Merge branch 'main' of git.sr.ht:~cdv/aoc-2020 into main
rs: need debug symbols in release mode

refs

main
browse  log 

clone

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

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

#Advent of Code 2020 Polyglot Solutions

Advent of Code is back again. And this time 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 rustc 1.50.0-nightly (1c389ffef 2020-11-24), 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

#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.

Day 18 uses leg to generate a small parser.

#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": 2020,
  "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 8.10.2 and cabal-install 3.2.0.0 to build the haskell solutions. The output is one aoc2020 binary that reads and runs every solution.

#Build and Run
cabal build :aoc2020
cabal run :aoc2020 -- 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"

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

{
  "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 = 2020
session = 'session token'
input_dir = '../input'

#Golang

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

usage: aoc2020 [-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.

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

#Ruby

Ruby 2.7.2. 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.

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

#.NET (C#)

I'm using .NET Core 3.1. Use dotnet build to build. The command accepts the following options:

aoc 1.0.0
Copyright (C) 2020 aoc

  -a, --all        (Default: false) Run all (availible) days

  -c, --config     (Default: aoc.json) Config file path

  -r, --refresh    (Default: false) Refresh inputs (always download)

  --help           Display this help screen.

  --version        Display version information.

  days (pos. 0)    Days to run

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

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