Solved

vb.net - generate specific word list

Posted on 2014-01-07
4
616 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 74

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now