Giter VIP home page Giter VIP logo

aoc-go's Introduction

Advent of Code in Go

A handy template repository to hold your Advent of Code solutions in Go (golang).

Advent of Code (https://adventofcode.com) is a yearly series of programming questions based on the Advent Calendar. For each day leading up to christmas, there is one question released, and from the second it is released, there is a timer running and a leaderboard showing who solved it first.


Features

  • A directory per question <year>/<day>
  • Auto-download questions into <year>/<day>/README.md
  • Auto-download example input into <year>/<day>/input-example.txt
  • With env variable AOC_SESSION set:
    • Auto-download part 2 of questions into <year>/<day>/README.md
    • Auto-download user input into <year>/<day>/input-user.md
  • When you save code.go, it will execute your run function 4 times:
    • Input input-example.txt and part2=false
    • Input input-example(2).txt and part2=true
    • Input input-user.txt and part2=false
    • Input input-user(2).txt and part2=true
    • Each run will display the return value and timing.
    • Part 2 will use the <file>2.txt if it exists.
  • Force execution of a specific:
    • Part with PART=<N> ./run.sh <year> <day> where N can be 1 or 2
    • Input with INPUT=<INPUT> ./run.sh <year> <day> where INPUT can be example or user

Usage

  1. Click "Use this template" above to fork it into your account

  2. Setup repo, either locally or in codespaces

    • Locally
      • Install Go from https://go.dev/dl/ or from brew, etc
      • Git clone your fork
      • Open in VS Code, and install the Go extension
    • Codespaces
      • Click "Open in Codespaces"
  3. Open a terminal and ./run.sh <year> <day> like this:

    $ ./run.sh 2023 1
    Created directory ./2023/01
    Created file code.go
    Created file README.md
    Created file input-example.txt
    run(part1, input-example) returned in 616µs => 42
  4. Implement your solution in ./2023/01/code.go inside the run function

    • I have provided solutions for year 2022, days 2,4,7 – however you can delete them and do them yourself if you'd like
  5. Changes will re-run the code

    • For example, update code.go to return 43 instead you should see:
    file changed code.go
    run(part1, input-example) returned in 34µs => 43
  6. The question is downloaded to ./2023/01/README.md

  7. Login to https://adventofcode.com

  8. Find your question (e.g. https://adventofcode.com/2023/day/1) and get your puzzle input and save it to ./2023/01/input-user.txt

    • See Session below to automate this step
  9. Iterate on code.go until you get the answer

  10. Submit it to https://adventofcode.com/2023/day/1


Session

Optionally, you can export AOC_SESSION=<session> from your adventofcode.com session cookie. That is:

  • Login with your browser
  • Open developer tools > Application/Storage > Cookies
  • Retrieve the contents of session
  • Export it as AOC_SESSION

With your session set, running code.go will download your user-specifc input-user.txt and also update README.md with part 2 of the question once you've completed part 1.

Currently, your session is NOT used to submit your answer. You still need to login to https://adventofcode.com to submit.

aoc-go's People

Contributors

chaines avatar

Watchers

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