Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Upwords IV: creating words with underpatterns

by tybalt89 (Monsignor)
on May 08, 2020 at 03:10 UTC ( [id://11116563]=note: print w/replies, xml ) Need Help??


in reply to Upwords IV: creating words with underpatterns

Something like this?

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11116556 use warnings; use Path::Tiny; my $dictionary = path( '/usr/share/dict/words' ); my @tiles = qw( a a d r t s c ); my $string = 'f e '; my $pat = join '', map "$_?", sort @tiles, $string =~ /\w/g; my $tilepat = join '', map "$_?", sort @tiles; my $letters = join '', @tiles, $string =~ /\w/g; print "$pat\n$tilepat\n"; my @matches = grep { ( join '', sort split // ) =~ /^$pat$/ } $dictionary->slurp =~ /^[$letters]{2,}$/gm; my @places; ($string =~ tr/ /./r) =~ /(?<!\w).{2,}(?!\w)(?{ push @places, $& })(*FAIL)/; @places = grep /\w/, @places; use Data::Dump 'dd'; dd \@places; my @matches1 = extension(1); print "@matches1\n\n"; my @matches2 = extension(2); print "@matches2\n\n"; sub extension { my $id = shift; my @found; for my $placepat ( $id == 1 ? @places : map expand($_), @places ) { for my $match ( @matches ) { $match =~ /^$placepat$/ or next; my $newtiles = $match & ($placepat =~ tr/.a-z/\xff\0/r); (join '', sort $newtiles =~ /\w/g) =~ /^$tilepat$/ and push @found, $match; } } return @found; } sub expand { grep /\w/, glob join '', map { /\w/ ? "{$_,.}" : $_ } split //, shif +t; }

Replies are listed 'Best First'.
Re^2: Upwords IV: creating words with underpatterns
by Aldebaran (Curate) on May 10, 2020 at 08:23 UTC
    Something like this?

    Yes, indeed, this seems to hit it on the head. It's all I can do to unravel it, but I have output, source and questions in readmore tags:

    So, bravo, tybalt89, this script is amazingly compact and effective. I just need a little help figuring it out as I test....

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-26 07:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found