tui/bin/anagram-finder.php

28 lines
829 B
PHP
Raw Normal View History

2026-08-21 21:34:02 +02:00
<?php
require __DIR__ . '/../autoload.php';
use Lvl0\AnagramFinder\Core\Matcher;
2026-08-22 20:00:35 +02:00
use Lvl0\AnagramFinder\TUI\ArgHandler;
use Lvl0\AnagramFinder\TUI\Output;
2026-08-21 21:34:02 +02:00
2026-08-22 20:51:50 +02:00
use function Laravel\Prompts\text;
2026-08-21 21:34:02 +02:00
const DICTIONARY = __DIR__ . '/../assets/words.txt';
2026-08-22 17:52:17 +02:00
Output::line("ANAGRAM FINDER");
$args = ArgHandler::make($argv);
2026-08-22 20:51:50 +02:00
$anagram = $args->get(1) ?: text("Enter the anagram", required: true);
$minLength = $args->get(2) ?: text(label: "Enter the minimum length of the results. (default=3)", placeholder: 3, default: 3, required: true);
2026-08-22 17:52:17 +02:00
$top10 = $args->hasOption('top');
2026-08-21 21:34:02 +02:00
2026-08-22 17:52:17 +02:00
Output::line();
Output::line("Results for your anagram: " . $anagram);
2026-08-21 21:34:02 +02:00
2026-08-22 17:52:17 +02:00
$matches = Matcher::findWords($anagram, $minLength);
if ($top10) {
$matches = $matches->slice(0, 10);
}
$matches->each(fn(string $word) => Output::line($word . " (" . strlen($word) . ")"));