Solved

vb.net - generate specific word list

Posted on 2014-01-07
4
714 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

632 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