Compare commits
No commits in common. "5e1da51506cd265399b88428e203c54a5b26e3a0" and "bdf707c2967c0b32057d2d1e88f1915b241a625e" have entirely different histories.
5e1da51506
...
bdf707c296
6 changed files with 467260 additions and 810 deletions
466550
assets/words.txt
Normal file
466550
assets/words.txt
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -1,12 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require __DIR__ . '/../autoload.php';
|
||||
|
||||
use Lvl0\AnagramFinder\TUI\Commands\FindAnagramWordsCommand;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$application = new Application('Anagram Finder', '1.0.0');
|
||||
$application->addCommand(new FindAnagramWordsCommand());
|
||||
$application->setDefaultCommand('anagram:find-words');
|
||||
$application->run();
|
||||
25
bin/anagram-finder.php
Normal file
25
bin/anagram-finder.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
require __DIR__ . '/../autoload.php';
|
||||
|
||||
use Lvl0\AnagramFinder\Core\Matcher;
|
||||
use Lvl0\AnagramFinder\TUI\ArgHandler;
|
||||
use Lvl0\AnagramFinder\TUI\Output;
|
||||
|
||||
const DICTIONARY = __DIR__ . '/../assets/words.txt';
|
||||
|
||||
Output::line("ANAGRAM FINDER");
|
||||
|
||||
$args = ArgHandler::make($argv);
|
||||
$anagram = $args->get(1) ?: readline("Enter the anagram: ");
|
||||
$minLength = $args->get(2) ?: 3;
|
||||
$top10 = $args->hasOption('top');
|
||||
|
||||
Output::line();
|
||||
Output::line("Results for your anagram: " . $anagram);
|
||||
|
||||
$matches = Matcher::findWords($anagram, $minLength);
|
||||
if ($top10) {
|
||||
$matches = $matches->slice(0, 10);
|
||||
}
|
||||
$matches->each(fn(string $word) => Output::line($word . " (" . strlen($word) . ")"));
|
||||
|
|
@ -4,8 +4,7 @@
|
|||
"type": "project",
|
||||
"require": {
|
||||
"anagram-finder/core": "^0.1.0",
|
||||
"illuminate/collections": "^13.26",
|
||||
"laravel/prompts": "^0.3.23"
|
||||
"illuminate/collections": "^13.26"
|
||||
},
|
||||
"license": "AGPL-3.0-only",
|
||||
"autoload": {
|
||||
|
|
|
|||
1427
composer.lock
generated
1427
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Lvl0\AnagramFinder\TUI\Commands;
|
||||
|
||||
use Lvl0\AnagramFinder\Core\Matcher;
|
||||
use Symfony\Component\Console\Attribute\Argument;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\Attribute\Option;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
|
||||
use function Laravel\Prompts\clear;
|
||||
use function Laravel\Prompts\info;
|
||||
use function Laravel\Prompts\spin;
|
||||
use function Laravel\Prompts\table;
|
||||
use function Laravel\Prompts\text;
|
||||
|
||||
#[AsCommand(name: 'anagram:find-words')]
|
||||
class FindAnagramWordsCommand extends Command
|
||||
{
|
||||
public function __invoke(
|
||||
#[Argument]
|
||||
?string $anagram,
|
||||
#[Argument]
|
||||
?int $minLength,
|
||||
#[Option]
|
||||
bool $top = false,
|
||||
): int {
|
||||
clear();
|
||||
|
||||
info("ANAGRAM FINDER");
|
||||
|
||||
$anagram = $anagram ??= text("Enter the anagram", required: true);
|
||||
$minLength = $minLength ?: text(label: "Enter the minimum length of the results. (default=3)", placeholder: 3, default: 3, required: true);
|
||||
|
||||
info("Results for your anagram: " . $anagram);
|
||||
|
||||
$matches = spin(
|
||||
callback: fn() => Matcher::findWords($anagram, $minLength),
|
||||
message: 'Checking wordlist...',
|
||||
);
|
||||
|
||||
if ($top) {
|
||||
$matches = $matches->slice(0, 10);
|
||||
}
|
||||
|
||||
table(
|
||||
headers: ["word", "length"],
|
||||
rows: $matches->map(fn(string $word) => ['word' => $word, 'length' => strlen($word)])->toArray(),
|
||||
);
|
||||
|
||||
return Command::SUCCESS;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue