Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: using perl to find words for scrabble

by tybalt89 (Monsignor)
on Sep 16, 2019 at 23:11 UTC ( [id://11106269]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11106269]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-18 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found