diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-11-29 20:23:02 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-11-29 20:23:02 +0100 |
| commit | 4c3a50166bf0f78ce89459c352cc1c6536a8b96d (patch) | |
| tree | 02e4b66a1435680ef1e92bf82576747b27f16447 /2024/php/day_04/Position.php | |
| parent | be2f8528b3829f8263507da301812d852297c168 (diff) | |
chore: make language folders snake_case
Diffstat (limited to '2024/php/day_04/Position.php')
| -rw-r--r-- | 2024/php/day_04/Position.php | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/2024/php/day_04/Position.php b/2024/php/day_04/Position.php new file mode 100644 index 0000000..0dcf96c --- /dev/null +++ b/2024/php/day_04/Position.php @@ -0,0 +1,79 @@ +<?php + +declare(strict_types=1); + +class Position implements Stringable +{ + public function __construct(public $x, public $y) + { + } + + public function __toString(): string + { + return "({$this->x}, {$this->y})"; + } + + /** + * Not validated + */ + public function getNorth(): self + { + return new self($this->x, $this->y - 1); + } + + /** + * Not validated + */ + public function getNorthEast(): self + { + return new self($this->x + 1, $this->y - 1); + } + + /** + * Not validated + */ + public function getEast(): self + { + return new self($this->x + 1, $this->y); + } + + /** + * Not validated + */ + public function getSouthEast(): self + { + return new self($this->x + 1, $this->y + 1); + } + + /** + * Not validated + */ + public function getSouth(): self + { + return new self($this->x, $this->y + 1); + } + + /** + * Not validated + */ + public function getSouthWest(): self + { + return new self($this->x - 1, $this->y + 1); + } + + /** + * Not validated + */ + public function getWest(): self + { + return new self($this->x - 1, $this->y); + } + + /** + * Not validated + */ + public function getNorthWest(): self + { + return new self($this->x - 1, $this->y - 1); + } +} |
