In the course of being asked to solve

some scrambled word puzzles, I wrote a Perl script that ran all possible permutations and checked them against a wordlist, but that was too slow, so I had to write something faster.
Of course, any technology can be turned into a japh...

After a while I'll post the original (non-JAPH) version, which is somewhat more flexible, legible, re-usable, and optionally verbose about its progress. Meanwhile, amuse yourselves with this...

$d='/usr/share/dict/words';# Adjust this to point to your dictionary w +ords file. @a=map _ ("",split//),qw'tjsu thanore arkceh';$^X=~/n\/(....)/;splice@ +a,2,@_,$+; sub _{my($f,@t)=@_;@c=('grep','-i','-e',"\"^$f".(join"",map".",@t).'$" +',$d);open _,"@c |";if(<_>){if(@t){my@l;for$i(0..$#t){my@e=@t;splice@e,$i,1;@r=_( +"$f$t[$i]" ,@e);for$r(@r){push@l,$r}}@l}else{$f}}else{return}};s(); $\ =pop@a;;pr +int"@a$/";

Replies are listed 'Best First'.
Re: Word unscrambler for POSIX systems...
by hv (Prior) on May 15, 2003 at 23:16 UTC

    I do a lot of this sort of thing, and over the course of the last couple of years I've built solutions to a variety of problems into this program I call 'word'. The -a option asks for an anagram:

    % word -da tsju /^(?:(?=.*u)(?=.*s)(?=.*j)(?=.*t).{4,4})\z/oi just juts %
    but it can do many other things.

    (Note that the program also assumes that this word-wrapper will be in the path, but that should be easy to hack out if not wanted.)

    Hugo