Coder Social home page Coder Social logo

advent-of-code-2021's Introduction

My Advent of Code 2021 solutions

https://adventofcode.com/2021. I may keep some notes here on the more interesting problems.

Solutions are labeled XXY for problem XX ("01" through "25"), part Y (either "a" or "b").

All solutions must be run from the top-level repo directory, with input on stdin, and will print the answer as the final line of output ( additional lines of debug/info may be printed before; pipe into tail -n1 to get only the answer).

Go solutions

All Go solutions are compiled into a single executable, the top-level package. To run solution XXY:

$ go run . XXY

For example: go run . 01a <inputs/1.input

JQ solutions

There is one JQ script per problem part. jq must be installed to run; to install on Mac with Brew, use brew install jq.

There are two ways to run solution XXY:

Standalone script

This is the preferred method, assuming your system has /usr/bin/env that can find jq (Brew ensures this). Just run:

$ pXX/pXXY.jq

For example: p01/p01a.jq <inputs/1.input

Manual run

First, open the JQ script file and copy all of the flags from the hashbang. For example, p02a.jq has:

#!/usr/bin/env jq -s -R -f

so your flags are -s -R -f. Then, run jq as follows:

$ jq [flags] pXX/pXXY.jq

For example: jq -s -R -f p02/p02a.jq <inputs/2.input

Scripts

Problem solving

These tools help speed up running/testing a solution. They're designed for Mac; YMMV on other platforms.

To load tools for problem X (note: single digit X for problems 1โ€“9), run:

$ . aoc.sh X

For example: . aoc.sh 1

This makes available the following bash functions, all acting for problem X:

$ get             # downloads main input as inputs/X.input, and the Z'th code block from problem as inputs/XY.sampleZ.input
$ samp[jq] Y [Z]  # runs Go (JQ) solution for part Y on code block Z (default 0)
$ run[jq]  Y      # runs Go (JQ) solution for part Y on main input (copies last output line to clipboard)

A typical sequence would go:

$ get     # download inputs
# ... write part A solution ...
$ samp a  # test part A; repeat as needed
$ run a   # run part A "for real"; repeat as needed, then paste answer to website
# ... repeat for part B ...

Setup

The solution templates (Go and JQ) were generated by running setup/setup.sh from the top repo directory.

advent-of-code-2021's People

Contributors

daboyuka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.