Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^3: Challenge: Generate a glob patterns from a word list

by tybalt89 (Monsignor)
on May 04, 2021 at 14:20 UTC ( [id://11132028]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Challenge: Generate a glob patterns from a word list
in thread Challenge: Generate a glob patterns from a word list

I think you are right, What we have here is a N-way diff (where N is the number of strings).
My guess is that it is horribly explosive in N.

A 2-way diff is bad enough that it takes caching to perform adequately. N-way would be much, much worse.

  • Comment on Re^3: Challenge: Generate a glob patterns from a word list

Replies are listed 'Best First'.
Re^4: Challenge: Generate a glob patterns from a word list
by choroba (Cardinal) on May 04, 2021 at 14:34 UTC
    In fact, my idea was to construct a finite state machine that accepted all the input words and minimise it. I was able to do that, but I was then unable to correctly interpret the states and transitions to create the output string.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
Re^4: Challenge: Generate a glob patterns from a word list (UPDATE)
by LanX (Saint) on May 04, 2021 at 17:34 UTC
    > My guess is that it is horribly explosive in N.

    I doubt it.

    Intuitively I'd say a two phase approach should work.

    • Build a tree like with a Trie
    • Parse the tree bottom-up and collapse it into a graph by using look-up hashes for duplicated sub-trees
    Since a Trie-tree isn't "exploding", this should be safe.

    Untested, of course.

    UPDATE

    Sorry, I should have read the examples in the OP more closely.

    I wasn't aware that

    • Or-groups were nested a{b,{c,d}}e (not even that it's possible)
    • empty alternatives were allowed a{b{,c}}d
    Without that my approach above should work.

    Now I'm rather pessimistic.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      Maybe a suffix tree could help?
      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Please see my update here, that's more complicated than I thought.

        This reminds me of what my prof called a "Minimales Wort Problem" in my studies, but I couldn't find a link for it.

        Basically finding the shortest algebraic term expressing a solution, the {,a,b} clauses are operations here.

        Problem now is that I doubt that there is always a unique minimal solution, which can be reached by a path of successive optimization steps.

        This means you have to try different steps in different order, which will indeed explode the complexity.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found