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

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";

Replies are listed 'Best First'.
Re^4: using perl to find words for scrabble
by tybalt89 (Monsignor) on Sep 17, 2019 at 00:59 UTC

    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";