Search
The Mesoamerican Research Center at the University of California launched project where large amount of public aerial photographs are automatically processed by computer in attempt to detect possible Mayan culture archaeological sites which are currently unknown. Wall remains under the surface can be detected using aerial photography, because stone structures hidden under the surface cause contrasting crop color in that area. Images were already preprocessed. Areas with contrasting crop color (possible wall remains) are marked by 1. Rest of the image contains zeros. Images are oriented regarding cardinal directions so there is north at the top of the image and west on the left side of the image. Next step is to detect and count house remains found in the image. House remaining has rectangular shape and consists of four walls. Notice that Mayans were building houses oriented regarding cardinal directions, thus all walls are oriented only in north-south or east-west direction. Each wall consists of pixels with value 1. Wall has exactly 1 pixel width and its length has to be at least 4 pixels. Pixel in the corner of a house is considered part of both walls that join in the corner. All pixels surrounded by walls forming a house remaining have to contain zeros only. Additionally, each pixel that is adjacent (horizontally, vertically or diagonally) to house remaining walls have to contain zeros only. Because the detection method is not perfect, it was decided that also structures which can be changed into house remaining by changing exactly one pixel value will be counted separately. Such structures are called possible house remains.
Create file main.py containing function find_solution. This function will take matrix as input parameter. Count the number of house remains and the number of possible house remains in the image and return those two numbers as a tuple.
Additional examples are shown bellow. Notice that in those examples input is not represented as Python 2D array (matrix). This is just for simplicity. Input provided by automatic evaluation will be Python matrix as shown in Starter Code bellow.
00000000000010111000 00111100000010001000 00100100000011111000 00111100000000000000 00000000000000000000 00000000001101111100 11111100000001000100 10000100000001010100 10000100000001000100 11111100000001111100 00000010111100000000 00000000100100000000 00000000100100000000 00000000111100000000
(1, 2)
011111100000000 010000100111000 010000100101010 011111100101010 000000000111011 111011100000000 111000000000000 111001111100000 000001000100000 000001000100000 000001111100000
(2, 0)
1111100000000000000000110 1000000000010011110000101 0011111110000010000000111 0010000010011110000110000 0010010010000000001010000 0010000010001110001010000 0011111110001110001010000 0000000000001110001110000 0000011100000000000000000 0000000000000111110000000 0001111001000100010001000 0001001000000111110000000 0001001000000001000011111 0001111000111111000100001 0000000000000010000100001 0000011000000000000111111
Below is a basic code structure you can use. Copy-paste the following code and complete the find_solution function according to the description above. Then submit your final main.py.
find_solution
main.py
def find_solution(matrix): """ >>> terrain_img = [ ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0], ... [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0], ... [0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0], ... [0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0], ... [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0], ... [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0], ... [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0], ... [1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0], ... [0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0], ... [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0] ... ] >>> find_solution(terrain_img) (1, 2) """ pass