Word Search ( Due 28 Jan 2022 )

Given an n by n grid of letters, and a list of words, find the location in the grid where the word can be found. A word matches a straight, contiguous line of letters in the grid. The match could either be done horizontally (left or right) or vertically (up or down) or along any diagonal either right to left or from left to right.

Input: The input will be in a file word_grid.in. Do not hard code the name of the file in your program. You will read the file from stdin. Here is the format of the input file. Assume that the format is correct; that is you do not have to do any error checking.

Output: There will be k lines in your output. Each line will have the word that you are to search, followed by a colon, followed by a single space and then the tuple giving the row and column where you found the word. In the tuple you will have two integers (i, j). The number i gives the row and the number j the column of the first letter of the word that you were required to find. Rows and columns are numbered conventionally, i.e. the first row is 1 and the first column is 1. If you do not find a word in the grid then the values for i and j will be 0 and 0. Use the full power of the built-in functions associated with strings and lists. This is the output for the given input file.

The file that you will be turning in will be called WordSearch.py. The file will have a template of the following form. You will follow the standard coding conventions in Python.


#  File: WordSearch.py

#  Description:

#  Student Name:

#  Student UT EID:

#  Partner Name:

#  Partner UT EID:

#  Course Name: CS 313E 

#  Unique Number:

#  Date Created:

#  Date Last Modified:

import sys

# Input: None
# Output: function returns a 2-D list that is the grid of letters and
#         1-D list of words to search
def read_input ( ):

# Input: a 2-D list representing the grid of letters and a single
#        string representing the word to search
# Output: returns a tuple (i, j) containing the row number and the
#         column number of the word that you are searching 
#         or (0, 0) if the word does not exist in the grid
def find_word (grid, word):

def main():
  # read the input file from stdin
  word_grid, word_list = read_input()

  # find each word and print its location
  for word in word_list:
    location = find_word (word_grid, word)
	print (word + ": " + str(location))

if __name__ == "__main__":
  main()

You may not change the names of the functions listed. They must have the functionality as given in the specifications. You can always add more functions than those listed.

For this assignment you may work with a partner. Both of you must read the paper on Pair Programming and abide by the ground rules as stated in that paper. If you are working with a partner then only one of you will submit the code. Make sure that in the header you have your name and UT EID and your partner's name and UT EID. You must use the group submission feature on Gradescope and mention your partner by name. If you are working alone then you will just have your name and your UT EID in the header.

Use the Canvas program to submit your WordSearch.py file. We should receive your work by 11 PM on Friday, 28 Jan 2022. We will be looking for clean logic and good documentation. There will be substantial penalties if you do not adhere to the guidelines.