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

Re: Next from inner loop only works "most of the time"

by tybalt89 (Prior)
on May 19, 2021 at 19:52 UTC ( #11132749=note: print w/replies, xml ) Need Help??


in reply to Next from inner loop only works "most of the time"

Why does your 'bad' run not show the %master_letter_freq hash like the 'good' run does? Can there be some problem in the calculation of that hash? Does the 'w' from the pattern get counted somehow? Is the 'w' from the pattern already on the board? If so, with a 'w' on your 'rack', words should be allowed to have two 'w's.

As a side note, my favorite way of answering the question "What words can be made with these letters?" is to match against a regex. Here's an example:

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11132707 use warnings; my $letters = 'otrwreh'; my $have = '...w'; # NOTE: using . instead of - my $pattern = join '', map "$_?", sort split //, $letters; my $regex = qr/^$pattern$/im; print "regex: $regex\n\n"; @ARGV = '/usr/share/dict/words'; /^$have$/i && (join '', sort /./g) =~ $regex && print while <>;

which outputs the computed regex and the matching words:

regex: (?^mi:^e?h?o?r?r?t?w?$) thew trow

this allows for only as many of a letter as initially specified.

Replies are listed 'Best First'.
Re^2: Next from inner loop only works "most of the time"
by Marshall (Canon) on May 20, 2021 at 07:41 UTC
    Good questions! A version of the full code using labeled next is posted at Re^2: Next from inner loop only works "most of the time".

    I actually first thought that there was some problem in the hashes. So I added some debug code to look at that issue. You can see what I did.

    I saw the error and then added debug stuff. That's why the good bad run doesn't have that info.

    You will see how I generated the regex. I did this in a straightforward way. My way generates some results that are not valid, but it was very easy to do while "hacking". Taking out a few extraneous results seemed to be a good way to go at the time. And it still seems like a good idea. A completely optimal regex is not necessary here.

    I made the interface so that I type in exactly the list of letters the puzzle presents. If there are 2 "e"'s, I type in 2 "e"'s.

Re^2: Next from inner loop only works "most of the time"
by Marshall (Canon) on May 20, 2021 at 08:20 UTC
    Now that I think about it, I make a separate reply, re: regex sets:

    I am assuming that a repeated letter in a regex set is "harmless". That /[icee][icee][icee]/ should match "ice".

    I am wondering if there is some regex weirdness if a letter repeats within a set?

      ... is [there] some regex weirdness if a letter repeats within a set?

      No. [icee] is exactly equivalent to [ice], [iceeee], [eiece], etc.


      Give a man a fish:  <%-{-{-{-<

        That is exactly what I thought. And why I did what I did.

        This UFO sighting is so weird, that I thought that covering all the bases is appropriate.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2021-09-16 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?