Solved

word search puzzle

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
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!
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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