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

Variables, Variables We cannot  go very far without variables. A variabl...

Variables We cannot  go very far without variables. A variable is a value related to a name that we can bind  to have a particular value  and  then  later use in an expression.

Program requests password to display information of author, Write a program...

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

Data wrangling, Ask quesICT702 TASK 2 1 2018 Semester 2 Data Wrangling Due ...

Ask quesICT702 TASK 2 1 2018 Semester 2 Data Wrangling Due in two parts - Friday of Week 9 and Week 12 Below Zero - ice cream store The local ice-cream store needs a new ordering s

If statements, how do you make an if and else statment work in pytho?

how do you make an if and else statment work in pytho?

Prime number, Use the function to compute and print the sum of first n prim...

Use the function to compute and print the sum of first n prime numbers.

Matrix, What are squared matrices?

What are squared matrices?

Angle between 2 moving line , how to calculate angle between 2 moving line ...

how to calculate angle between 2 moving line in 2d space

Non-local references in procedures, Non-local references in procedures ...

Non-local references in procedures There  is an important subtlety in the  way  names  are handled in the  environment created by a function call. When  a value  that  is not

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