Add dictionary link
This commit is contained in:
parent
961c060309
commit
10ec71b76a
1 changed files with 3 additions and 1 deletions
|
|
@ -7,6 +7,8 @@ use Illuminate\Support\LazyCollection;
|
||||||
|
|
||||||
class Matcher
|
class Matcher
|
||||||
{
|
{
|
||||||
|
private const DICTIONARY = __DIR__ . '/../assets/words.txt';
|
||||||
|
|
||||||
public static function findWords(string $anagram, int $minLength = 3): Collection
|
public static function findWords(string $anagram, int $minLength = 3): Collection
|
||||||
{
|
{
|
||||||
$matches = self::getWordList()
|
$matches = self::getWordList()
|
||||||
|
|
@ -38,7 +40,7 @@ class Matcher
|
||||||
private static function getWordList(): LazyCollection
|
private static function getWordList(): LazyCollection
|
||||||
{
|
{
|
||||||
return LazyCollection::make(function () {
|
return LazyCollection::make(function () {
|
||||||
$fh = fopen(DICTIONARY, 'rb');
|
$fh = fopen(self::DICTIONARY, 'rb');
|
||||||
try {
|
try {
|
||||||
while (($line = fgets($fh)) !== false) {
|
while (($line = fgets($fh)) !== false) {
|
||||||
yield rtrim($line, "\r\n");
|
yield rtrim($line, "\r\n");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue