Skip to content

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels

Notifications You must be signed in to change notification settings

i-geo/adventofcode-php

Repository files navigation

adventofcode-php

PHP solutions to Advent of Code tasks.

All tasks are Advent of Code ownership. This repository represents my solutions to Advent of Code algorithmic tasks using PHP.

Directory structure

  • Puzzles, e.g.

    src/Puzzle/Year[YEAR]/Day[DAY]_TaskName
        Part1.php           # Part1 solution
        Part2.php           # Part2 solution
    
  • Tests, e.g.

    tests/Puzzle/Year[YEAR]/Day[DAY]_TaskName
        Part1Test.php           # Part1 solution test
        Part2Test.php           # Part2 solution test
    
  • Docs

adventofcode-php is completely dockerized.

If you have docker installed:

  1. Pull adventofcode-php project
  2. Open console and change directory to project root
  3. Run the following command:
docker-compose up -d
  1. If you need to enter a running container:
docker exec -it adventofcode-php_app_1 /bin/bash

Puzzle adding and testing

  1. New puzzle needs to be added in src/Puzzle/Year2020/Day1DescriptionOptional/Part1.php directory
  2. Puzzle solution method needs to inherit App\Puzzle\PuzzleInterface interface
  3. Puzzle can be run from project root using CLI command
puzzle:run <year> <day> <part> <puzzle_input>

e.g.

php bin/console puzzle:run 2020 1 1 '91212129'
  1. Also you can open puzzle in your favorite browser, e.g.
http://localhost/src/Puzzle/Year2020/Day1DescriptionOptional/Part1.php

Multiline input

Multiline input can be pasted to CLI using quotes. Both single quotes and double quotes work.

php bin/console puzzle:run 2020 1 1 '1721
  979
  366
  299
  675
  1456'

Tests

PHPUnit is used for testing puzzles also:

Tests can be run using command:

./vendor/bin/phpunit tests/

Copyright and License

Copyright (c) 2021 Ivan Georgiev Licensed under the MIT License

About

Advent of Code is an Advent calendar of small programming puzzles for a variety of skill sets and skill levels

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published