blob: 60a16a0176571e77111499fec27bc8869a1091f7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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);
}
}
|