On Tue, Apr 09, 2002 at 05:41:22PM +0000, Jean-Pierre Vidal wrote: > This is a fact. At the time, I dont understand why I could not see the output > words were in the input :-(
At first I had a similar problem. I started writing a program to recursively generate all anagrams. Then I re-read the rules and saw they were in the input file. This lead to the following program: #!/usr/bin/perl -ln $w{$_}=1; END{ for(keys %w){ split(//); $e{$_}=[sort grep {$w{$_}-->0} g(@_)]; } for(sort {$#{$a} <=> $#{$b} || ${$a}[0] cmp ${$b}[0]} values %e){ print @{$_} if $#{$_}>0; }; } sub g{ return @_ if (!$#_); my(@a,@q,$l); while($l=shift){ push @a,map {$l.$_} g(@q,@_); push @q,$l; } return @a; } Which was rejected (which I can fully understand) because it 'didnt finish'. I still think it is a correct solution, but it would be hard to find a way to be even slower :) CU, Sec (Hoped he could beat `/anick, but failed - maybe next time :-) -- The most successful method of programming is to begin a program as simply as possible, test it, and then add to the program until it performs the required job." -- PDP8 handbook, Pg 9-64