[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

word search puzzle

Posted on 2014-04-29
2
Medium Priority
?
1,282 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 41

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 500 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 500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

650 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