Skip to content

mokorana/advent-of-code-2024

Repository files navigation

My attempts at the Advent of Code 2024 challenges in PHP.

Solutions

Day Name Code Time † GitHub Action Output
01 Historian Hysteria src/Day01.php 0.003701s Day-01
02 Red-Nosed Reports src/Day02.php 0.014919s Day-02
03 Mull It Over src/Day03.php 0.001430s Day-03
04 Ceres Search src/Day04.php 0.018255s Day-04
05 Print Queue src/Day05.php 3.213716s Day-05
06 Guard Gallivant src/Day06.php 70.499905s Day-06
07 Bridge Repair src/Day07.php 4.580957s Day-07
08 Resonant Collinearity src/Day08.php 0.003884s Day-08
09 Disk Fragmenter src/Day09.php 42.189519s Day-09
10 Hoof It src/Day10.php 0.028195s Day-10
11 Plutonian Pebbles src/Day11.php 0.016682s Day-11
12 Garden Groups src/Day12.php 11.519407s Day-12
13 Claw Contraption src/Day13.php 0.318790s Day-13
14 Restroom Redoubt src/Day14.php 1.774646s Day-14
15 Warehouse Woes src/Day15.php 0.039639s Day-15
16 Reindeer Maze src/Day16.php 1,011.829665s Day-16
17 Chronospatial Computer src/Day17.php 224.071246s Day-17
18 RAM Run src/Day18.php 8.305735s Day-18
19 Linen Layout src/Day19.php 0.142203s Day-19
20 Race Condition src/Day20.php 13.676298s Day-20
21 Keypad Conundrum src/Day21.php TBD Day-21
22 Monkey Market src/Day22.php 23.460746s Day-22
23 LAN Party src/Day23.php 0.069283s Day-23

† The measured execution time in GitHub Actions

Installation

Installing on your machine

Installation with vary on each system. For a full environment the following dependencies should be installed:

Installing with Docker

Using Docker avoids the complexity of installing the dependencies listed above.

Once Docker is installed, a Docker image can be built by running:

make docker-build

Once built, an interactive shell with the project directory mounted can be started by running:

make shell

How to run

Before running the code, the dependencies must be installed by running:

composer install

All puzzles can be executed by running:

php src/main.php

Individual puzzles can be executed by adding the day-number:

php src/main.php 01

The solutions can be benchmarked by adding the flag -b:

php src/main.php 01 -b

Why is the input data encrypted?

Note that the input data included in this repository have been encrypted, and exist purely for personal use. This is because the input data is the sole property of Advent of Code, and is not licensed for reproduction or distribution. To test with your own input, replace the contents of the file src/Day**.data with your own inputs from adventofcode.com.

If you somehow are in possession of the encryption key, you can unlock it using git-crypt by running:

echo "${BASE64_ENCODED_KEY}" | base64 -d | git-crypt unlock -

How to develop

As mentioned above, the code for each puzzle can be run individually. But this project has additional tools to help with development.

Generate Quiz Files

Some files have to be generated for every new quiz day. Those files can be automatically generated.

make generate 01 'name of quiz'

Tests

Test-driven-development using unit tests can help with solving a puzzle by ensuring individual functions work as expected. Tests can be added in tests/Unit/* and run using PHPUnit. The flags --testdox and --colors can help make the output more legible:

vendor/bin/phpunit tests/Unit/Day01Test.php --testdox --colors

This can be run quickly for all tests from the Makefile:

make tests

Note that some of the test data includes sample data from adventofcode.com, which have been encrypted for the same legal reasons mentioned above in "Why is the input data encrypted?". These tests will be skipped when attempting to run the tests.

Linting & Static Analysis

Following code standards can help make the code more legible and running static analysis tools can spot issues in the code. This project comes with PHP CodeSniffer and Psalm:

vendor/bin/phpcs -p --standard=PSR12 src/ tests/
vendor/bin/psalm --show-info=true

These can be run quickly from the Makefile:

make lint

About

Solutions to Advent of Code 2024 in PHP

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published