The Real cha0s
Order emerges out of cha0s :)

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!

Reply

  • E-Mail addresses are hidden with reCAPTCHA Mailhide.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
Prove you're a human!