diff options
| author | DJ O'Leary <dijitol@proton.me> | 2025-03-03 00:56:33 +0100 |
|---|---|---|
| committer | DJ O'Leary <dijitol@proton.me> | 2025-03-03 00:56:33 +0100 |
| commit | e24effa8fd3574e9d396be0e1a47f101c27c0a60 (patch) | |
| tree | 793896d20384facd10d925e09f8f0dd89c930cce /2024/OCaml/lib/day_04/php/Input.php | |
perf: Merge Advent of Code year specific repos
Diffstat (limited to '2024/OCaml/lib/day_04/php/Input.php')
| -rw-r--r-- | 2024/OCaml/lib/day_04/php/Input.php | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/2024/OCaml/lib/day_04/php/Input.php b/2024/OCaml/lib/day_04/php/Input.php new file mode 100644 index 0000000..f7e03c1 --- /dev/null +++ b/2024/OCaml/lib/day_04/php/Input.php @@ -0,0 +1,25 @@ +<?php + +declare(strict_types=1); + +class Input +{ + public string $contents; + + public function __construct(private string $fileName) + { + $contents = file_get_contents($this->fileName, use_include_path: true); + $this->contents = $contents === false ? "" : $contents; + } + + public function toGrid(): Grid + { + $lines = explode("\n", $this->contents); + $gridArray = array_map( + callback: fn(string $line): array => str_split(trim($line)), + array: $lines + ); + + return new Grid($gridArray); + } +} |
