Compare commits
2 commits
bdf707c296
...
5e1da51506
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e1da51506 | |||
| 12bd79396f |
6 changed files with 810 additions and 467260 deletions
466550
assets/words.txt
466550
assets/words.txt
File diff suppressed because it is too large
Load diff
12
bin/anagram-finder
Executable file
12
bin/anagram-finder
Executable file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/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();
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
<?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,7 +4,8 @@
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"anagram-finder/core": "^0.1.0",
|
"anagram-finder/core": "^0.1.0",
|
||||||
"illuminate/collections": "^13.26"
|
"illuminate/collections": "^13.26",
|
||||||
|
"laravel/prompts": "^0.3.23"
|
||||||
},
|
},
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|
|
||||||
1427
composer.lock
generated
1427
composer.lock
generated
File diff suppressed because it is too large
Load diff
53
src/Commands/FindAnagramWordsCommand.php
Normal file
53
src/Commands/FindAnagramWordsCommand.php
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
<?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