Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that reads in a square grid of numbers and find the largest n digit number that occurs left-to-right. Write a program that

Write a program that reads in a square grid of numbers and find the largest n digit number that occurs left-to-right.
image text in transcribed
image text in transcribed
image text in transcribed
Write a program that reads in a square grid of numbers and find the largest nin digit number that occurs laft-to-right Load Grid Function The Ioad_.gridi) function takes a filename, reads the contents of the file and returns the square gid as a list of lists. f tlenase = "orid_5 by_5. txt" grtd = load_grtd(ftlenane ) 8. returns {[8,3,5,0,9],[8,4,4,5,1],[9,1, 2,3,2],[2,7,5,6,7],[7,7,1,3,3]] Print Grid Function There is a print. grida() function that will take a list of tlats Pthenane - "orta_5,by-5, txt" prtat_grtdtgrtd) print(nax_nun_in_rows(grid, 3)) \& prints 912 print(aax_num_adv(grtd, 3)) \# prints 971 help you visualise the grid. Max Number in Rows Function The max_num_in_rows() function takes in a square grid of numbers as a list of lists and the number of digits n to search for. It should find the maximum n-digit number. Here is an example for the following grid. 83689 84451 91232 27567 77133 The function should work as follows: \# grid stored in grid_5_by_5.txt grid =[[8,3,6,8,9],[8,4,4,5,1],[9,1,2, 3,2],[2,7,5,6,7],[7,7,1,3,3]] print(max_num_in_rows(grid, 2)) \# prints 91 print(max_num_in_rows(grid, 3)) \#prints 912 print(max_num_in_rows(grid, 4)) \# prints 9123 Advanced The max_num_adv() function is similar to the max_num_in_rows() function but should find the largest n-digit number that occurs either: - left-to-right - top-to-bottom - diagonally top-left-to-bottom-right - diagonally bottom-left-to-top-right For the 55 grid example, 83689 84451 91232 27567 77133 the function should work as follows: \# grid stored in grid_5_by_5, txt grid=[[8,3,6,8,9],[8,4,4,5,1],[9,1,2, 3,2],[2,7,5,6,7],[7,7,1,3,3]] print(max_num_adv(grid, 2)) \# prints 97 print(max_num_adv(grtd, 3)) * prints 971 print(max_num_adv(grid, 4)) \# prints 9127

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design A Practical Approach

Authors: Marilyn Campbell

1st Edition

1587193175, 978-1587193170

More Books

Students also viewed these Databases questions