Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

combinations between words!

by khaled_diaa (Initiate)
on Jun 20, 2007 at 10:45 UTC ( #622217=perlquestion: print w/ replies, xml ) Need Help??
khaled_diaa has asked for the wisdom of the Perl Monks concerning the following question:

dear great monks, a new guy needs assistance, i have been required to create a script to generate all possible cmombinations between words. and by combinations i mean that if i have 5 words i need all possible sentences between those 5 words. the words are read from a file, i read them and place them in a 2d array this is where i got so far! need help badly!

Comment on combinations between words!
Re: combinations between words!
by marto (Chancellor) on Jun 20, 2007 at 10:50 UTC
Re: combinations between words!
by guinex (Sexton) on Jun 20, 2007 at 12:10 UTC
    You wouldn't be trying to get us to do your homework would you? :)

    -guinex

Re: combinations between words!
by Limbic~Region (Chancellor) on Jun 20, 2007 at 12:25 UTC
    khaled_diaa,
    You likely do not mean combinations. This is because with combinations, there is not difference between "I love you" and "you I love". So before pointing you to some modules that will make your life easier, why don't you answer a few questions:
    • Do all 5 words have to be used in every sentence or can a sentence use 3 of the 5 words for instance?
    • Can words only appear once, or can they be re-used?
    • Do you have more than 5 words and you need to choose 5 at a time?
    • etc, etc, etc
    There are a number of modules that can help you solve this problem. If you had searched on CPAN for combination and/or permutation, I bet you would have gotten further than you did.

    Cheers - L~R

Re: combinations between words!
by Moron (Curate) on Jun 20, 2007 at 12:36 UTC
    "This and that and the other" from "this and that the other"? if allowed and the program is written correctly, it should loop forever ;)

    To put it another way and to expose the unknowns more thoroughly, you need to specify whether order of the words matters (yes=permutation no=combination) and whether words may repeat (yes=something two orders of magnitude more complicated than either!)

    __________________________________________________________________________________

    ^M Free your mind!

Re: combinations between words!
by ikegami (Pope) on Jun 20, 2007 at 13:23 UTC
    Tip: It might be easier to put the words in an array and permute/combine the indexes of the array.
Re: combinations between words!
by blazar (Canon) on Jun 20, 2007 at 14:58 UTC

    dear great monks, a new guy needs assistance,

    You welcome! Did you use to be a gal previously? ;-)

    i have been required to create a script

    Required by whom? Your teacher? Your instructor? What did you try thus far?

    to generate all possible cmombinations between words.

    Combinations or Permutations? Or...

    and by combinations i mean that if i have 5 words i need all possible sentences between those 5 words.

    A sentence is a linguistics concept, and not all the of the permutations of a given list of words will give you a well formed sentence according to some grammar. Don't you think so?

    the words are read from a file, i read them and place them in a 2d array

    In a 2d array? And according to which criteria?

Re: combinations between words!
by GrandFather (Cardinal) on Jun 20, 2007 at 19:16 UTC

    It would help if you showed us your code so far with a small data set (say three words) and the output you expect. It may also help if you tell us why you are doing this. At present it looks like poorly specified homework and we have an aversion to doing homework.


    DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://622217]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-10-31 21:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (224 votes), past polls