Solved

vb.net - generate specific word list

Posted on 2014-01-07
4
649 Views
Last Modified: 2014-01-08
Hello there,
I have a list of 100 words for example

dog
cat
bird
monkey
mouse
fish
whale
horse
chicken

I would like to know how can I generate a unique and complete list using 3 words
something like this

chicken_cat_whale
horse_fish_mouse

etc..
0
Comment
Question by:XK8ER
4 Comments
 
LVL 30

Expert Comment

by:Brad Howe
ID: 39764073
Does order or repetition count?
0
 
LVL 1

Author Comment

by:XK8ER
ID: 39764097
dog_dog_cat doesnt work
dog_cat_dog  doesnt work

they must be different.. the order doesn't matter..
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 39764812
Put all 100 words in array, and apply for loop over 100 words; take a new hashtable, create a string of 3 words combining with underscore(_). Add this key value pair in hashtable, before adding you can check whether string is already added or not..

Hope this will help you.
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39766324
Using LINQ:

Module Module1
    Sub Main()
        Dim wordList As New List(Of String)() From
        {
            "dog",
            "cat",
            "bird",
            "monkey",
            "mouse",
            "fish",
            "whale",
            "horse",
            "chicken"
        }

        Dim query = From firstWord In wordList
                    From secondWord In wordList
                    From thirdWord In wordList
                    Where firstWord <> secondWord AndAlso
                          firstWord <> thirdWord AndAlso
                          secondWord <> thirdWord
                    Select String.Format("{0}_{1}_{2}", firstWord, secondWord, thirdWord)

        For Each item In query
            Console.WriteLine(item)
        Next

        Console.ReadKey()
    End Sub
End Module

Open in new window


The multiple From effectively give you a Cartesian join of all the words. Then it simply becomes a matter of excluding the ones you don't want--in this case, the ones containing duplicates.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question