Advent Of Code 2021 in PHP

New nostalgic Advent of Code in PHP! I worked in PHP for many years, so this time I want to remind those days to myself. To see the original tasks for all days and previous years, visit https://adventofcode.com/. All credits to them for this nice work!

See each day for more information. I copied the instructions there as well.

How to run

  1. Install PHP 8+ and Composer https://getcomposer.org/download/
  2. Clone this repo
  3. Install dependencies with php composer install
  4. Run:
    • php start.php to execute runner
    • php vendor/bin/phpunit to start tests
    • php vendor/bin/phpcs to run linter

Running with Docker

If you don't want to install PHP locally, I suggest to use ./php bash script which will execute it in PHP docker. To download Composer locally use this

wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
./php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
./php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
./php composer-setup.php
./php -r "unlink('composer-setup.php'); unlink('installer.sig');"

If you have problem with ./php composer-setup.php remove from ./php temporarily the part --user "$(id -u):$(id -g)"

Then it remains the same, just use ./php instead of php

Days I got stuck and searched for the help

  • Day 20: I did not realized the endless pane will be changing from zeros to ones and back... The hint from Kobzol was required.
  • Day 21: I failed with 2 points here. So I went to Reddit for some help and I have found others having same questions.
    • I did not realized, that in Part 2 each player roll dice 3 times. So not creating 3 universes, but 3x3 universes. Reddit link
    • I had no idea how to solve it. So I reached for another topic, where the concept of maximum 44100 combinations was described. Reddit link

Days