#!/usr/bin/perl # authored by Josh Goldberg <josh@3io.com> # Jan 10, 2004 # # ARGV[0] is a string of letters, ARGV[1] is a dictionary file. # the script searches the dictionary for all combinations/permutations # of the ARGV[0] that have at least three characters and no character +is # repeated. # Originally authored for use with the widgetWords konfabulator widget +. use Algorithm::Permute; $|=1; $resultstoprint = 7; $defaultDictionary = "joshWordList.txt"; @tilePoints = ( 100,300,300,200,100,400,200,400,100,800,500,100,300,10 +0,100,300,1000,100,100,100,100,400,400,800,400,1000 ); $vowels = ( 65,69,73,79,85,89 ); $common = ( 84,78,83,72,82,68,76 ); sub combinations { my @list= @_; my @pick= (0) x @list; return sub { my $i= 0; while( 1 < ++$pick[$i] ) { $pick[$i]= 0; return if $#pick < ++$i; } return @list[ grep $pick[$_], 0..$#pick ]; }; } $file = $ARGV[1] || $defaultDictionary; die "missing dictionary" unless -e $file; @letters = split //,lc $ARGV[0]; # permute all combinations of 3-8 letters $combinations = combinations(@letters); while (@comb = $combinations->() ) { next unless scalar @comb > 2; $p = new Algorithm::Permute(\@comb); while (@res = $p->next) { local $"=''; $wordlist{"@res"} = 1; } } open LIST, "<$file"; while (<LIST>) { chomp; $dict{$_} = 1; } foreach $word (keys %wordlist) { if (exists $dict{$word}) { push @matches, $word; @res = split //,$word; $score = 0; for (@res) { $score += $tilePoints[ord(uc $_)-65]; } $len = scalar @res; $score += $len * 50; $score += 400 if $len == 8; $wordlist{$word} = $score; } } close LIST; print "top Eight Words:\n"; @sorted = reverse sort {$wordlist{$a} <=> $wordlist{$b} } @matches; for (@sorted) { if ($resultstoprint > 0) { last if $top++ > $resultstoprint; } @res = split //,$_; print "$_: $wordlist{$_} points\n"; } exit 0;
In reply to Re: Finding words within a character set
by bageler
in thread Finding words within a character set
by ruhk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |