in reply to using perl to find words for scrabble
#!/usr/bin/perl # https://perlmonks.org/?node_id=11105638 use strict; use warnings; use Path::Tiny; my @words = grep /^[a-z]{4,}\z/ && /[aeiouy]/, # lc, size & vow +el path('/usr/share/dict/words')->lines({chomp => 1}); my @tiles = map +('a' .. 'z')[rand 26], 1 .. 9; print "tiles: @tiles\n"; my @matches; my $pattern = join '', map "$_?", sort @tiles; for my $word ( @words ) { if( join('', sort split //, $word) =~ /^$pattern$/ ) { push @matches, $word; } } print "\nmatches:\n\n@matches\n";
Typical output:
tiles: h l n l q g a l o matches: along gall gallon goal hall halo halon hang hogan llano loan loll long
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: using perl to find words for scrabble
by Aldebaran (Curate) on Sep 16, 2019 at 22:31 UTC | |
by tybalt89 (Monsignor) on Sep 16, 2019 at 23:11 UTC | |
by tybalt89 (Monsignor) on Sep 17, 2019 at 00:59 UTC |