Program to solve word search puzzles, Python Programming

This assignment involves writing a program to solve word search puzzles. For example in the following word grid it is possible to find the words active, stock, ethernet and java. Note that this exercise involves only horizontal and vertical words; words that occur diagonally (such as python) are not considered as being present in the grid.


1 Inputting the Grid from a File

In the file write code to prompt the user for a filename, and attempt to open the file whose name is supplied. If the file cannot be opened the user should be asked to supply another filename; this should continue until a file has been successfully opened.

The file will contain on each line a row from the grid. For example the first two lines of a file that contains the grid shown on the previous page would be


Write code to read, in turn, each line of the file, remove the newline character and append the resulting string to a list of strings.

After the input is complete the grid should be displayed on the screen.

Note that grids used for testing the submitted programs may have different widths and heights from the sample one that will be provided. Grids may be assumed to contain only lower-case letters and all rows in a grid will have the same length.


2 The Word-Search Function

Write a function that will take two arguments: a word to be searched for and a list of strings containing the grid.

The function should searchfor a horizontal (left-to-right or right-to-left) or vertical (downwards or upwards) occurrence of the word (e.g. activex and ethernet in the sample grid). If a word occurs more than once the function is required to find only one occurrence, so you should stop searching once the word has been found.

[ It is recommended that you first write a function that just searches for horizontal occurrences and then write the code for section 2.3 to allow the function to be tested before adding code to the function to search for vertical occurrences. ]

If the word has not been found None should be returned; if the word has been found the function should return a tuple, containing details of where the word is located. The tuple should contain either the coordinates of the first and last letters of the word (i.e. four integers) or the coordinates of the first letter and a direction (i.e. two integers and a string).

3 The Word-Search

After displaying the grid, the program should ask the user to supply a name of a file containing words to be searched for, one word per line. This file should be opened, once again asking the user to supply another name if necessary. You should supply each word in this file in turn to the word-search function. If the function returns None the word should be added to a set of words that have not been found; otherwise the tuple returned should be added as a value in a dictionary using the word as a key.

Aftersearching for all of the words you should display details of all words in the dictionary (in alphabetical order) using a format such as

active found: row 2 col 2 to row 2 col 7


active found: left to right in row 2 starting at col 2

Finally you should output a list of the words that were not found (also in alphabetical order).

Posted Date: 2/21/2013 4:33:03 AM | Location : United States

Related Discussions:- Program to solve word search puzzles, Assignment Help, Ask Question on Program to solve word search puzzles, Get Answer, Expert's Help, Program to solve word search puzzles Discussions

Write discussion on Program to solve word search puzzles
Your posts are moderated
Related Questions
Every programming language has to have  some method for indicating grouping of operations. Here is how you execute an if-then-else structure in Java:   if (s == 1){ s = s

#question.Program 10 Assignment (Banking Objects – Savings/Checking Accounts) Create a program named that performs the following: Create a class named ChkAcct, and a class n

Structured data We will often  want  to work  with  large  groups of data.   Rather  than  providing  each  number its own  value,  we need  to manage the data  into natural s

In English, specify a representation of the board game in Python. The representation should capture the entire state of the game at one point in time. It may be helpful to first fi

Import the sample code below into the Python IDLE and enhance it, run it and debug it. Add features to make this a more realistic database tool by providing for easy data entry an

inputWithinRange (prompt, lowValue, highValue) This function will ask for a number using the prompt parameter. The function will only return a value that is within the inclusive ra

Booleans   Before we talk about  conditionals, we require  to clarify the Boolean  data  type.  It has two values False and True. Typical statement that have Boolean values

what is python

python program of motion of a particle in viscus medium

draw the variation of pressure with volume of a real gas at temperatures lower than its critical temperature.also draw its surface of discontinuity