Question
Using Python, Consider an m by n chessboard with the squares labeled (0,0),(0,1),...,(m-1,n-1). 1. Write a function friendly_pair() which takes in two squares and tells
Using Python, Consider an m by n chessboard with the squares labeled (0,0),(0,1),...,(m-1,n-1).
1. Write a function friendly_pair() which takes in two squares and tells whether or not two rooks on those squares are threatening each other. We want it to return True if the rooks are not threatening each other and False if they are. Note that this function does not need to take in the size of the board.
>>> friendly_rooks((0,0),(0,3))
False
>>> friendly_rooks((0,0),(3,3))
True
>>> friendly_rooks((0,0),(3,0)) False
2. Write a function friendly_group() which takes in a list or tuple of positions and returns False in any pair of DIFFERENT rooks in those positions are threatening each other. Otherwise it should return True.
>>> friendly_group(((0,0),(1,1)))
True
>>> friendly_group(((0,2),(1,1),(2,0)))
True
>>> friendly_group(((0,2),(1,1),(2,1)))
False
>>> friendly_group(((0,2),(1,1),(2,4),(3,3)))
True
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started