Search
Quotes I love
We need not fear the expression of ideas; we do need to fear their suppression.
-Harry Truman
-Harry Truman
Reply to comment
PHP anagram finder!
This code will find an anagram on a Linux or Mac machine that has a dictionary installed! Nothing big, but have fun!
#!/usr/bin/php
<?
$word = $argv[1];
$greps = 'grep ' . implode(" | grep ", str_split($word));
$length = strlen($word);
$candidates = explode("\n", `cat /usr/share/dict/words | $greps | egrep '^[a-z]{{$length}}$'`);
print implode("\n", array_filter($candidates, function($e) use ($word) {
$w = str_split($word);
$c = str_split($e);
asort($w);
asort($c);
return implode('', $w) == implode('', $c);
})) . "\n";
$ anagram lestab ablest bleats stable tables
^^ Yay!
