Solved

word search puzzle

Posted on 2014-04-29
2
1,149 Views
Last Modified: 2014-05-04
I want to write a  C# console application for a word search puzzle (similar to scrabble game). There is a file with collection of letters which contains hidden words (puzzle.txt). I need to find all of the words in the word list (words.txt) from puzzle.txt.

These words may the words hidden left to right (LR) ,right to left (RL), up(U), down(D), Diagonal up left (DUL), Diagonal up right (DUR), Diagonal down left(DUL) or Diagonal down right (DDR).

The output should include name of the word found, where it was found and the direction like (up or down, etc)

puzzle.txt

COOSGNDLOODINTIOIS
LNGMAKCEANDOROSRUC
IAEASPTLTAIPONRND
CNFIREWALLWREIKOOC
KFDPRDHTOOTHULBASH

words.txt

Bash
cookie
Tooth
Click
Firewall

Any suggestions on how to approach this in C# or provide pseudocode?
Thanks in Advance.
0
Comment
Question by:welcome 123
2 Comments
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
ID: 40032363
I would load each line into an char array.

From there start at 0,0

for each row
{
 for each column
 {
   for each UNMATCHED word
   {
      check each direction  //careful not to go out of bounds
     
        if match, remember location for word, then continue //2 words can start using same later
   }
    next column
 }
  next row
}

not the most efficient most likely, but straight forward and easy to understand.
0
 
LVL 16

Accepted Solution

by:
George Tokas earned 250 total points
ID: 40033985
My approach - even though same in principle - would be:
1. Load the puzzle.txt lines in a 2 dimensional array...
2. depending on search pattern create a new string by reading the array.
First horizontal left to right is the the first line, the reverse is hor. right to left.
Search for each word inside the string.
3. repeat with the next or till all words found.

for the search inside the string you can use String.IndexOf(search_word).
If it returns a value >=0 you found the word inside the string.

George Tokas.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Service Controller 1 23
C# bracket error 3 30
Winform Module - What is the ASP.Net equiv 2 19
Call Controller Action Method from ASPX 2 14
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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