Solved

word search puzzle

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
network + 7 73
Adding WebGrid Checkbox Column checked by default 3 27
Is IHttpActionResult a promise pattern? 2 37
Image(2) 3 28
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video discusses moving either the default database or any database to a new volume.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now