in reply to Re: unglue words joined together by juncture rules
in thread unglue words joined together by juncture rules
> Still to do: decompose each possibility into dictionary words.
This just happens to be similar to something I've been fiddling with recently.
#!/usr/bin/perl -w my $str = "cowboycatdog"; chomp(my @list = sort { length($b) <=> length($a) } <DATA>); for my $word (@list){ my $tmp = $str; next unless $tmp =~ s/$word//; my @results; push @results, $word; my @rem = grep ! /^$word$/, @list; for my $w (@rem){ push @results, $w if $tmp =~ s/$w//; } next if length($tmp); push @out, \@results; } print "'$str' has the following anagrams:\n\n", map "@$_\n", @out; __DATA__ cowboy cow boy cat do dog
The output looks like this:
'cowboycatdog' has the following anagrams: cowboy cat dog cow boy cat dog boy cow cat dog cat cowboy dog dog cowboy cat
|
|---|