0


I have to write a function that takes a list of string(words that vary in length), and an int(size of data set eg. int value of 4 will be 4 columns and four rows in table), and with this I must produce a crossword like block(block being the dataset) that will hold as many of the words in the list as possible, like a crossword they can cross each other if the letters match at the right places, and the words must be all mixed up, read in every direction(like a crossword puzzle).

I can't seem to find code to help me with this, so far I have the basic structure of the dataset, here it is, any help will be appreciated, thanks.

public WordsDs WordMixer(List<string> wordList, int size)
{
    if ((wordList == null) || (size < 2))
    {
        return null;
    }

    //shuffle the words in the list so that they are in a random order
    Random random = new Random();
    var sortedList = wordList.OrderBy(i => random.Next()).ToList();

    //create a dataset for the words
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();

    //add columns and rows according to the size parameter
    for (int i = 0; i < size; i++)
    {
        dt.Columns.Add(i.ToString(), typeof(string));
    }
    for (int i = 0; i < size; i++)
    {
        dt.Rows.Add(i);
    }


    for (int i = 0; i < wordList.Count; i++)
    {



    }//for (int i = 0; i < wordList.Count; i++)

}
tshepang
  • 12,111
  • 21
  • 91
  • 136
  • 3
    I'm a little confused about what you mean by "read in every direction". Do you mean a crossword: http://en.wikipedia.org/wiki/Crossword ? Or a Word Search: http://en.wikipedia.org/wiki/Word_search ? – DGH Dec 09 '10 at 09:22
  • BTW, that is not the best way to shuffle --> http://stackoverflow.com/questions/1287567/c-is-using-random-and-orderby-a-good-shuffle-algorithm – digEmAll Dec 09 '10 at 09:48
  • You need to compare all your words in your list one by one and check if they are longer than int size. You can't put a 10 letter word into 4*4 dataset if you are planning on putting 1 letter to every cell. I suggest you to randomly put your words into your dataset (letter by letter) and fill the rest of your dataset with random letters. If this is what you need, I can write the code for it and I'm sure it'd be fun :) – Pabuc Dec 09 '10 at 09:50

1 Answers1

2

You could just use a two-dimensional array to hold the characters. I guess the tricky part is from the word list work out where there a letter is shared between two words. I guess start with the least frequently used letter and work from there!

Interesting Article
http://blogs.teamb.com/craigstuntz/2010/01/11/38518/

Stack Overflow Question may help (although in c++ - might be of use)
Best data structure for crossword puzzle search

Other links to code generators.
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=6082&lngWId=10
http://dotnetslackers.com/articles/net/Creating-a-programming-crossword-puzzle.aspx
One in c
http://pdos.csail.mit.edu/cgi-bin/theme-cword

Community
  • 1
  • 1
Aim Kai
  • 2,934
  • 1
  • 22
  • 34