in reply to Re: using perl to find words for scrabble
in thread using perl to find words for scrabble

Typical output:

...indeed, as I can replicate. Thanks for your post. Yours has the advantage of getting up and running quickly and having some form of probability to try different combinations.

C:\Users\tblaz\Documents\evelyn>perl 1.tyb.pl >1.tyb.txt C:\Users\tblaz\Documents\evelyn>type 1.tyb.txt tiles: o o y o q p i p g matches: goop goopy pipy pogy poop yogi C:\Users\tblaz\Documents\evelyn>

I know, poop, ha-ha, but who knew pipy and pogy were english words?

It seems to me that the method of letter generation should reflect the distribution of a given game and that a hash would be the appropriate data structure to do so. What is an elegant way to initialize the 26 key-value pairs? Frankly, there has to be a lot of initialization to pull off any game....

distribution of letters in scrabble

Thanks for your comments

Replies are listed 'Best First'.
Re^3: using perl to find words for scrabble
by tybalt89 (Monsignor) on Sep 16, 2019 at 23:11 UTC

    Simple way to do letter frequency:

    #!/usr/bin/perl # https://perlmonks.org/?node_id=11105638 use strict; use warnings; use Path::Tiny; my @letters = split //, 'aaaaaaaaabbccddddeeeeeeeeeeeeffgggghhiiiiiiii +ijkllllmmnnnnnnooooooooppqrrrrrrssssttttttuuuuvvwwxyyz'; my @tiles = @letters[map rand @letters, 1 .. 9]; print "tiles: @tiles\n"; my $pattern = join '', map "$_?", sort @tiles; my @matches = grep join('', sort split //) =~ /^$pattern$/, grep /^[@tiles]{2,}\z/ && /[aeiouy]/, # lc, size & vowel path('/usr/share/dict/words')->lines({chomp => 1}); print "\nmatches:\n\n@matches\n";

      Actually, this has the chance of selecting more than one 'q'.
      The following is a better way.

      #!/usr/bin/perl # https://perlmonks.org/?node_id=11105638 use strict; use warnings; use Path::Tiny; use List::Util qw( shuffle ); my @letters = split //, 'aaaaaaaaabbccddddeeeeeeeeeeeeffgggghhiiiiiiii +ijkllllmmnnnnnnooooooooppqrrrrrrssssttttttuuuuvvwwxyyz'; my @tiles = ( shuffle @letters )[0 .. 8]; print "tiles: @tiles\n"; my $pattern = join '', map "$_?", sort @tiles; my @matches = grep join('', sort split //) =~ /^$pattern$/, grep /^[@tiles]{2,}\z/ && /[aeiouy]/, # lc, size & vowel path('/usr/share/dict/words')->lines({chomp => 1}); print "\nmatches:\n\n@matches\n";