0% found this document useful (0 votes)
43 views1 page

ITLabAssign 3

This document provides instructions for Assignment-3 which is due on January 15th, 2021. It describes a number maze problem where the goal is to move a token from the top left corner to the bottom right corner of an nXn grid. On each turn, the token can move up, down, left, or right based on the number on its current square. Students are asked to write a program that takes a number maze as input, converts it to a graph, and uses BFS to find the minimum number of moves to solve the maze or outputs that no solution exists. The program should be able to solve mazes of size n=1000 within 1-2 minutes.

Uploaded by

Dolly Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

ITLabAssign 3

This document provides instructions for Assignment-3 which is due on January 15th, 2021. It describes a number maze problem where the goal is to move a token from the top left corner to the bottom right corner of an nXn grid. On each turn, the token can move up, down, left, or right based on the number on its current square. Students are asked to write a program that takes a number maze as input, converts it to a graph, and uses BFS to find the minimum number of moves to solve the maze or outputs that no solution exists. The program should be able to solve mazes of size n=1000 within 1-2 minutes.

Uploaded by

Dolly Alam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Assignment-3 (Due 15th January 2021)

A number maze is an nXn grid of positive integers. A token starts in the upper left
corner; your goal is to move the token to the lower-right corner. On each turn, you are
allowed to move the token up, down, left, or right; the distance you may move the
token is determined by the number on its current square. For example, if the token is
on a square labeled3, then you may move the token three steps up, three steps down,
three steps left, o rthree steps right. However, you are never allowed to move the
token off the edge of the board. For example, given the number maze in Figure., your
algorithm should return the integer 8.

Write a program that asks for an input file that contains the input number maze M , and
outputs the minimum number of moves required to solve the maze; if the maze does not
admit a solution, your program should output that. There is no need to output the actual
sequence of moves. For full credit, your program should be able to correctly solve inputs of
length n = 1000 reasonably fast, say within a second to two minutes. (Input files will be
uploaded)
We can convert the number maze M into graph and use BFS on this graph to find a solution.
First, we make each number in the number maze a vertex. Thus there are a total of n 2 vertices
corresponding to an n×n maze. Then for each vertex Mi,j, we read its value k in the number
maze and connect Mi,j to Mi+k,j, Mi−k,j, Mi,j+k, Mi,j−k (provided these vertices exist).
Once the graph is completely constructed, we can use BFS to find a shortest path from the
vertex corresponding to the top-left square to the vertex corresponding to the bottom-right
square.

You might also like