Skip to content

James Thatcher's solutions for Advent Of Code 2021 in PHP 8.1

Notifications You must be signed in to change notification settings

jthatch/advent-of-code-2021-php

Repository files navigation

Advent of Code 2021 PHP

The solutions to advent of code 2021, solved using PHP 8.1. By James Thatcher

Solutions 🥳🎉

🎄 Day 1 🎅 Day 2 ☃️ Day 3 🦌 Day 4 🍪 Day 5 🥛 Day 6 🧦 Day 7 🎁 Day 8Day 9 🛐 Day 10Day 11 & Class 🧝 Day 12 & Class 🎅 Day 13

About

My attempts at tacking the awesome challenges at Advent of Code 2021 using PHP 8.1.

Unlike my solutions for AOC 2020, where I used array_* functions and aimed for maximum efficiency, this year I'm using the excellent Collections package that comes with Laravel. This lets me do common array manipulation without effort, and not losing much in the way of performance. Although as you'll see, I still love a good recursive function 😉

day runner in action

Commands

Note: checkout the code then run make run. The docker and composer libraries will auto install.

Solve all days puzzles
make run

Solve an individual days puzzles
make run day={N} e.g. make run day=13

Solve multiple days puzzles
make run day={N},{N1}-{N2}... e.g. make run day=1-5,7,10,10,10 Runs days 1-5, 7 and 10 3 times

Solve a single part of a days puzzles
make run day={N} part={N} e.g. make run day=16 part=2

Create the next days PHP file and download puzzle from server
Auto detects what current Day you are on and will create the next (only if the files don't exist)

make next
# Created new file: src/Day8.php
# Fetching latest input using day=8 AOC_COOKIE=53616c7465645f5f539435aCL1P
# ./input/day8.txt downloaded

Use XDebug
make xdebug

Xdebug can also be triggered on a single days and/or part
make xdebug day={N} e.g. make xdebug day=13 or make xdebug day=13 part=2

IDE settings:

  • 10000 - xdebug port
  • aoc-2021 - PHP_IDE_CONFIG (what you put in PHPStorm -> settings -> debug -> server -> name)
  • /app - absolute path on the server
  • see xdebug.ini if you're stuck