Program to solve word search puzzles, Python Programming

Assignment Help:

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


Related Discussions:- Program to solve word search puzzles

Print vs return, Print vs Return Here are two different method declara...

Print vs Return Here are two different method declarations: def f1(x): print x + 1 def f2(x): return x + 1 What happens when  we call them? >>> f1(3) 4 >>

Homework Assignment #4, Finally! After years of adding unimportant sports,...

Finally! After years of adding unimportant sports, the IOC has finally added Shoe Tying to the Olympics. And you’ve been selected to write the software to handle the judging of t

CIS, Define a function that draws a pentagon of a size you provide when you...

Define a function that draws a pentagon of a size you provide when you call the function. Include a ''''''docstring'''''' as the first line of the function''s body — it tells the p

Algorithms, Write an algorithm for the sum of the given series 1,-1/2,1/4,-...

Write an algorithm for the sum of the given series 1,-1/2,1/4,-1/8.....

Python programs, Python programs Every  general-purpose computer has a...

Python programs Every  general-purpose computer has a various detailed design, which  defines  that  the way  its program requires  to be specified is different. The "machine

Programming embedded systems- interact with the environment, Interacting wi...

Interacting with the environment Computer systems have  to communicate with  the world around them,  getting information about  the external world, and  taking  actions  to cha

Graphing data, Write a program that will take price data for stocks and pri...

Write a program that will take price data for stocks and print it graphically to the screen. Your program should begin by asking the user for the file name. It should then create a

Indentation and line breaks, Every programming language has to have  some m...

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

Common errors and messages, Common Errors and Messages Here are some co...

Common Errors and Messages Here are some common Python errors  and error  messages to look  out for. Please let us give if you have any favorite additions for this list.

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd