id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

peter@norvig.com > queens_attack
prev  |  next  |  chance

In Chess, a Queen can move any number of spaces in a straight line: horizontally, vertically, or diagonally. Write the function queens_attack(n, Q1, Q2), which should return if queen Q1 attacks queen Q2 (that is, Q1 can move to Q2's position). The paramater n is an integer saying the size of the board; for a regular chess board it will be 8, indicating an 8 x 8 board. Both Q1 and Q2 will be specified in the form of a pair, [c, r], indicating the column and row number (going from 0 to n-1).


queens_attack(8, [1, 1], [7, 7]) → True
queens_attack(8, [1, 1], [2, 3]) → False
queens_attack(8, [1, 1], [2, 0]) → True

...Save, Compile, Run (ctrl-enter)

def queens_attack(n, Q1, Q2):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Post-solution available

Copyright Nick Parlante 2017 - privacy