Solved

word search puzzle

Posted on 2014-04-29
2
1,227 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
[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
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

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

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

728 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