Solutions to puzzles from https://adventofcode.com.
I am running this code with PHP 8.3 on a Mac. YMMV with other setups.
By default, the puzzle inputs are saved to the filesystem after the initial request to the AoC site.
The request requires a session cookie from the AOC website. To configure:
-
Log in to https://adventofcode.com.
-
Use the developer tools in your browser to get the value of the
sessioncookie for the AoC website.
-
Save the value of the cookie to an environment variable named
AOC_SESSION.export AOC_SESSION=536....
If you don't want to set an AOC_SESSION environment variable, you can manually create the files in path/to/repo/<year>/puzzle_inputs. Filenames should look like day_01.txt.
Use the new_puzzle.php script to generate new puzzle files.
php new_puzzle.php --year=2024 --day=1 --title="Historian Hysteria"Use the solve.php script to run the solver for a given day and year.
php solve.php --year=2024 --day=1 Use the --test flag to test a solver against the example inputs from the AoC website.
php solve.php --year=2024 --day=1 --test# output
Historian Hysteria (test)
Part 1: 11
Part 2: 31Like the puzzle inputs, test inputs are saved to the filesystem after the initial request to the AoC site. Test inputs are assumed to be in the largest <code> block on the puzzle page. This request does not use the AOC_SESSION environment variable.
Alternately, you can manually create the files in path/to/repo/<year>/test_inputs and fill them with the appropriate data. Filenames should look like day_01.txt.
This repo follows the automation guidelines on the /r/adventofcode community wiki.
- Outbound calls are throttled to one every 5 minutes
aoc_request()inAdventOfCode
- Once inputs are downloaded, they are cached locally
get_input()inAdventOfCode
- The User-Agent header includes the url of this GitHub repo and my email address
aoc_request()inAdventOfCode
This repo also follows the redistribution guidelines from https://adventofcode.com/about.
- Does not include puzzle text
- Does not include puzzle inputs