A robot starts on a point marked “A” on a rectangular grid of points. The starting point is always the top left point on the grid. The robot can move left, right, up or down, moving from one point to the next. By moving in steps going left, right, up or down, the robot would like to reach a point marked “B”, which is always the bottom right point in the grid. Sometimes, points are marked as “x”, and the robot is not allowed to visit them at all. A robot is never allowed to visit a point more than once. In how many ways can the robot move from A to B and visit all points along the way? For example, in the following grid, represented in text as A   .   .  .   .   B  there is only one path from A to B: In the following grid, represented in text as A   .   . x   x  B there is still only one path (we're lucky because of the two x's): However, in the grid A   .   .  .   x  B there are no ways for the robot to move from A to B and visit all points that are not marked with “x”. Write a single file of Python code that can be used to count the number of paths from A to B for any given input grid. Inside this file, your code should call a function that has the following boilerplate format: def count_paths(input_string):     # parse the string input here, possibly calling other functions that you’ve     # written in your Python code file     # possibly call other functions that you’ve written in your Python code     # file to count the number of paths     # return the (integer) number of paths return number_of_paths If your code was called with input_string = 'A . . .\n. . . B' number_of_paths = count_paths(input_string) print(number_of_paths) the number 0 should be printed. If your code was called with input_string = 'A . . .\n. . . .\n. . . .\n. . x B' number_of_paths = count_paths(input_string) print(number_of_paths) a number larger than one should be printed. We’ll leave it to you to determine what it is. Your code doesn’t have to run on grids larger than 10x10 points, and should only make use of the Python Standard Library. Please upload your .py file here.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

A robot starts on a point marked “A” on a rectangular grid of points. The starting point is always the top left point on the grid. The robot can move left, right, up or down, moving from one point to the next. By moving in steps going left, right, up or down, the robot would like to reach a point marked “B”, which is always the bottom right point in the grid.

Sometimes, points are marked as “x”, and the robot is not allowed to visit them at all. A robot is never allowed to visit a point more than once.

In how many ways can the robot move from A to B and visit all points along the way?

For example, in the following grid, represented in text as

A   .   .

 .   .   B 

there is only one path from A to B:

In the following grid, represented in text as

A   .   .

x   x  B

there is still only one path (we're lucky because of the two x's):

However, in the grid

A   .   .

 .   x  B

there are no ways for the robot to move from A to B and visit all points that are not marked with “x”.

Write a single file of Python code that can be used to count the number of paths from A to B for any given input grid. Inside this file, your code should call a function that has the following boilerplate format:

def count_paths(input_string):

    # parse the string input here, possibly calling other functions that you’ve

    # written in your Python code file

    # possibly call other functions that you’ve written in your Python code

    # file to count the number of paths

    # return the (integer) number of paths return number_of_paths

If your code was called with

input_string = 'A . . .\n. . . B'

number_of_paths = count_paths(input_string)

print(number_of_paths)

the number 0 should be printed. If your code was called with

input_string = 'A . . .\n. . . .\n. . . .\n. . x B'

number_of_paths = count_paths(input_string)

print(number_of_paths)

a number larger than one should be printed. We’ll leave it to you to determine what it is.

Your code doesn’t have to run on grids larger than 10x10 points, and should only make use of the Python Standard Library.

Please upload your .py file here.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Can you say anything about the complexity of the problem?

How much longer do you guess it will take to obtain an answer for a 100x100 grid compared to a 10x10 grid? And a 1x10 grid compared to a 10x10 grid? Can you postulate some general rules of thumb?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education