473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Count words in a grid

You have a grid like this:

Y Y F O U R
G F O U R G
F O U R Y G
G U R U O F
Y R Y R Y G

How many times does this grid have FOUR in it?

How should I make something that accepts a word and seeks in a Grid for
example? You can also go diagonal.

For example the F on (2, 0) can do FOUR horizontally, FOUR vertically,
BUT also:

F
O U R

or

F
O
U R

etc...
--
Thanks in advance,

Stijn Verrept.
Aug 1 '06 #1
2 1460
I think u can use "Deep First" search

"Stijn Verrept" wrote:
You have a grid like this:

Y Y F O U R
G F O U R G
F O U R Y G
G U R U O F
Y R Y R Y G

How many times does this grid have FOUR in it?

How should I make something that accepts a word and seeks in a Grid for
example? You can also go diagonal.

For example the F on (2, 0) can do FOUR horizontally, FOUR vertically,
BUT also:

F
O U R

or

F
O
U R

etc...
--
Thanks in advance,

Stijn Verrept.
Aug 1 '06 #2
Loop through all of the characters in the grid until you find a letter 1 ...
when you have found a letter 1 compare all of its neighbors to a letter 2
(repeat for the rest of the letters). Your termination point is when you
can't find the next letter.

consider ...
Y Y F O U R
G F O U R G
F O U R Y G
G U R U O F
Y R Y R Y G
I pass the two ys as they are not my first letter 'F' .. I get to the 3'rd
letter which is an F .. I begin comparing its neighbors.

-1,0 Y ... next
-1,-1 F ... next
0,-1 O ... thats my next letter recurse to search its neighbors (if you only
support straight lines i.e. diag vert etc this becomes much more efficient
as you only have a single recursive test but you wanted all so you have to
iterate through all of its neighbors)
..
..
..
..
eventually you find the word on 0,-1 ... you save the word and move to the
next neighbor from the first node .. +1,0 which is an F ... again recurse
its neighbors find O .. etc.

It is also important to NOT check the node that you came from .. this may
sound silly but consider the word mississippi

M I S S
X P J I
V P KM
Z I Q R

if you don't remember where you came from the algorithm will allow you to
reuse those letters when searchin neighbors as in the example above where
the iss gets reused.
Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Stijn Verrept" <TURN_moc.tfosyrtne@njits_AROUNDwrote in message
news:Qf********************@scarlet.biz...
You have a grid like this:

Y Y F O U R
G F O U R G
F O U R Y G
G U R U O F
Y R Y R Y G

How many times does this grid have FOUR in it?

How should I make something that accepts a word and seeks in a Grid for
example? You can also go diagonal.

For example the F on (2, 0) can do FOUR horizontally, FOUR vertically,
BUT also:

F
O U R

or

F
O
U R

etc...
--
Thanks in advance,

Stijn Verrept.

Aug 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Ling Lee | last post by:
Hi all. I'm trying to write a program that: 1) Ask me what file I want to count number of lines in, and then counts the lines and writes the answear out. 2) I made the first part like this: ...
9
by: dan | last post by:
this is a program to count average letters per word. i am able to count the total number of letters, but not words. How do you count the total number of words in a text file, so i am able to divide...
1
by: James | last post by:
Access 2003, trying to count the number of records that meet a criteria. According to Help: "In the Database window, click Queries under Objects, and then click New on the database window...
11
by: Foodbank | last post by:
Hello, I'm trying to develop a program that will enable me to count the number of words in a text file. As a plus, I'd like to be able to count how many different words there are too. I have a...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
8
by: Doug Bell | last post by:
Hi, I need to create a function that will return the number of columns in a passed reference to a DataView. I can find the number of columns in its underlying Data table but have not been...
9
by: aaron | last post by:
I have a few documents in which I need to get a total word count. Can anyone help? I'd like to create this program so I can get the result after entering the filename, and have the option to...
0
by: mike0870 | last post by:
Hi, I've been at this one for hours and cannot not find any posts of anyone having the same problem. Ther scenario is, I need to fill a drop down box with a value in the grid row to pass to the...
3
by: waynejr25 | last post by:
can anyone debug my program and get it to run. #include <fstream> #include <iostream> #include <string> #include <cstdlib> #include <map> using namespace std;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.