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.

xmmycxvtljlqbbybkoumjqwbtbufve
buubmekxbeydqmcnzyjpvdankomdmi
lqactivexnyvwdvcoshoyrohgvfvqj
vsewohvnbxsduqjiffkoyhpdwbrngc
dvqwwwfkoyamapmlrrjvtkljpcvkua
iqqfxtumsjvfmtrsbycyqiarixqikp
afgrvlqzdqaxaoanfqplmjpjhnzams
yofywrbpfcjiflcbbcoecxpwljyuyt
twyxetyuyufvvmcuawjmbwlqhxjgqo
txekdexmdbtgvhpyvsqtmljdxeqltc
dcctenrehteoxqdgnueljtrrnesgok
oqsnakqwerouftmgnjqbytjzhmwncc

1 Inputting the Grid from a File

In the file ex2.py 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

xmmycxvtljlqbbybkoumjqwbtbufve
buubmekxbeydqmcnzyjpvdackomdmi

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

or

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
I need server, client and trusted side communicating and charging a service with that protocol (or needham shroeder)

Ask question #Minimum 100 worIn this project, create the pseudo code from the following request. The program must have some sort of menu that allows users to make selections to

Procedures in Firrst-class objects In Python, unlike  many  other  languages, methods are behave in much  the same way as num­ bers:  they  can be stored as values  of variabl

Bank transfer What  if we  have  two  values,  representing bank  accounts, and  need  to transfer an  amount of money  amt between them?  Consider that a bank account is show

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. N

Your task is to construct a translator from the subset of Python in Project 3 intocontinuation-passing style (CPS). Of course, the expected way of accomplishing this is to trans

In Python, the fundamental abstraction of a computation is as a procedure (other  books call them "functions" instead; we will end  up  using  both  values).   A function that  tak

Write a program that requests a password after the author/program information is displayed. Make the password "hello". The program should then ask the user for their name: if the n

We encourage you to adopt an interactive style of debugging and programming. Use the Python shell a lot. Write short pieces of code and check them.  It is much  simpler to test the

What if you had a list of integer values, and you need to add  them  up and give the sum?  Here are a number of different types of doing  it. First,  here  is a type in a style