summaryrefslogtreecommitdiff
path: root/php/2024/day_04/Input.php
diff options
context:
space:
mode:
authorDJ O'Leary <dijitol@proton.me>2026-06-26 18:04:09 +0200
committerDJ O'Leary <dijitol@proton.me>2026-06-26 18:04:09 +0200
commit6d8fb621d1e93b83786890d6d9cb6f0d8defa8ae (patch)
tree17c90d3984c114aa023600cc5bec6f6004b02243 /php/2024/day_04/Input.php
parentad4ea5ca4bc9f7540ee1d6a4fa2d881709dc6459 (diff)
refactor!: invert repo directory structure
now is language first
Diffstat (limited to 'php/2024/day_04/Input.php')
-rw-r--r--php/2024/day_04/Input.php25
1 files changed, 25 insertions, 0 deletions
diff --git a/php/2024/day_04/Input.php b/php/2024/day_04/Input.php
new file mode 100644
index 0000000..60a16a0
--- /dev/null
+++ b/php/2024/day_04/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);
+ }
+}