Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6255187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T14:19:06+00:00 2026-05-24T14:19:06+00:00

I’m working on a game and I’m struggling to get some generic functionality. Suppose

  • 0

I’m working on a game and I’m struggling to get some generic functionality. Suppose we have a phrase like "puzzle game using group of words" so I generate possible subsets from this:

"puzzle", "game", "using", "group", "of", "words" and to add more fun I also add group of two consecutive words (for now groups of > 2 words are not allowed): "puzzle game", "game using", "using group", "group of", "of words"

So now the main idea would be forming ALL possible combinations from these subsets that form the original sentence. Please note that in this case the subsets should be a partition.

Example:

"puzzle game", "using", "group", "of words"
"puzzle", "game", "using group", "of", "words"

…

Not allowed:

"puzzle game", "game using", .. (it's not a partition as "game" is repeated)

Is there any known algorithm that generates all possible combinations? I presume this can get very time consuming for longer phrases so are there alternatives that try to find possible best options based on some weight for example?

I don’t pretend to get code (though that would be awesome) but at least any tip or ideas of where to look at would be really appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T14:19:06+00:00Added an answer on May 24, 2026 at 2:19 pm

    first parse your string into words, let the list of words be S. create an empty result list (let it be L) of possible return values.

    use a recursive solution: set a current solution (initialized to empty), and at each step – add the possible next word/double to it. when you used up your words, the ‘current’ will be a partition, and add it to the list.

    pseudocode:

    partitions(S,L) = partitions(S,L,{})
    
    partitions(S,L,current):
       if S is empty: 
            L.add current
       else:
            first <- S.first
            second <- S.second
            partitions(S-{first}-{second},L,current+{first second})
            partitions(s-{first},L,current+{first})
    

    EDIT: note: this solution assumes only 1 or 2 words are legal per partition. if it is not the case, instead of the hard-coded recursive call which decreases S by 1/2 words, you will have to iterate over the 1,…,S.size() first words.

    None recursive solution (using Stack and List ADTs):

    partitions(S):
       L <- empty_result_list()
       stack <- empty_stack()
       stack.push(pair(S,{}))
       while (stack is not empty):
          current <- stack.pop()
          S <- current.first
          soFar <- current.second
          if S is empty:
              L.add(soFar)
          else:
              stack.push(pair(S-{S.first}-{S.second},soFar+{S.first S.second})
              stack.push(pair(S-{S.first},soFar+{S.first})
       return L
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have thousands of HTML files to process using Groovy/Java and I need to
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.