GithubHelp home page GithubHelp logo

advent-of-code's Introduction

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels that can be solved in any programming language you like. If you want to solve it in PHP, this library can help you with common tasks as input downloading or solutions running.

Installation & Setup

At first, install AdventOfCode for PHP as dependency via composer:

composer require pavelsterba/advent-of-code

It will add CLI located in vendor/bin/aoc. With it, you can configure it with:

php vendor/bin/aoc dotenv

How to find my session cookie

One important think you need is value of your session cookie when you are logged in on Advent of Code website. Some small differences may exists between different browser, but basic way to find it is:

  1. Go to Advent of Code website.
  2. Make sure you are logged in.
  3. Open Developer Tools with F12.
  4. Go to Application tab.
  5. In left menu, click on Cookies item and select Advent of Code domain.
  6. Find cookie with name session and copy its value.

Value of this cookie is sensitive information! Make sure it will not be commited publicly, so add .env (where is it stored in your computer) into .gitignore.

CLI commands

dotenv

php vendor/bin/aoc dotenv [options]
Options:
  -y, --year=YEAR        Which year should be added as current
  -s, --session=SESSION  Session token for Advent of Code

Generate .env file during setup.

input

php vendor/bin/aoc input [options] [--] <day>
Arguments:
  day                                 Which day to download

Options:
  -y, --year=YEAR                     Which year should be downloaded
  -f, --force                         Download input without cache

Download input data for given day. It also creates boilerplate code for your solutions (more about it later).

run

php vendor/bin/aoc run [options] [--] <day>
Arguments:
  day                   Which day to run

Options:
  -y, --year=YEAR       Which year are you solving
  -f, --first           Run first solution
  -s, --second          Run second solution
  -t, --test            Run on test data

Run solutions from generated boilerplate.

Solutions

If you download input data with CLI and generate boilerplate, you will see that this library created some folder and files:

2022
└─ day-1
   ├─ intput.txt
   ├─ intput-test.txt
   └─ solution.php

input.txt contains input data for your puzzle.

input-test.txt is by default empty file, but its purpose is to add example input data for puzzle to be able to run your solution against small dataset with expected output.

solution.php is main file for your solutions. It contains two method - first() and second() for easier and harder part of puzzle. Just return your solution value and run it.

advent-of-code's People

Contributors

pavelsterba avatar

Stargazers

Alan Wynn avatar Nicolas Beauvais avatar

Watchers

 avatar  avatar

advent-of-code's Issues

Add User-Agent to request

Advent of Code receives a lot of abusive traffic from automated scripts and tools that identify themselves in the User-Agent header with worthless information like python-requests/x.y.z; to which Eric will most likely block access.

To avoid being banned, ensure that your script's User-Agent header contains your contact information. (Specifically, the contact info of the person that maintains the code sending the automated requests, not the contact info of the person using the script.)

Bonus points if you also include a URL where Eric can check out your script!

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.