summaryrefslogtreecommitdiff
path: root/2024/OCaml/lib/day_04/php/Grid.php
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2025-03-03 01:14:16 +0100
committerDJ O'Leary <dijitol@proton.me>2025-03-03 01:14:16 +0100
commit6860b6e83f2c6be5e59253105cf397c5b27b1590 (patch)
treeb4dbad23c012f4e547e5df1d24361818cee50b9a /2024/OCaml/lib/day_04/php/Grid.php
parent4da9eabd1223682c50209c7659537aaa0867a107 (diff)
feat: Move 2024 php files
Diffstat (limited to '2024/OCaml/lib/day_04/php/Grid.php')
-rw-r--r--2024/OCaml/lib/day_04/php/Grid.php67
1 files changed, 0 insertions, 67 deletions
diff --git a/2024/OCaml/lib/day_04/php/Grid.php b/2024/OCaml/lib/day_04/php/Grid.php
deleted file mode 100644
index c0382df..0000000
--- a/2024/OCaml/lib/day_04/php/Grid.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-class Grid implements Stringable
-{
- /**
- * @param string[][] $data
- */
- public function __construct(public array $data) {}
-
- public function __toString(): string
- {
- $rowToLine = fn(array $row): string => array_reduce(
- array: $row,
- callback: fn(string $acc, string $character): string => $acc . $character,
- initial: "",
- );
-
- return array_reduce(
- array: $this->data,
- callback: fn(string $acc, array $row): string => $acc . $rowToLine($row) . PHP_EOL,
- initial: "",
- );
- }
-
- public function getCharacterAtPosition(Position $position): string
- {
- if ($this->isInBounds($position)) {
- return $this->data[$position->y][$position->x];
- }
-
- return ".";
- }
-
- /**
- * @param Position[] $positions
- */
- public function getStringFromPositions(array $positions): string
- {
- $characters = array_map(
- callback: fn(Position $position): string => $this->getCharacterAtPosition($position),
- array: $positions,
- );
-
- $string = array_reduce(
- array: $characters,
- callback: fn(string $acc, string $character): string => $acc . $character,
- initial: "",
- );
-
- return $string;
- }
-
- public function isInBounds(Position $position): bool
- {
- if (!array_key_exists($position->y, $this->data)) {
- return false;
- }
-
- if (!array_key_exists($position->x, $this->data[$position->y])) {
- return false;
- }
-
- return true;
- }
-}