Learn how to write the code for checking whether any two queens on the same diagonal threaten each other.
- [Instructor] Okay, now for the slightly…more difficult one.…So, we can test whether two queens are on the same row…which gets us some of the way there.…We also need to test whether two queens find themselves…on the same diagonal.…And so, that means we have to calculate the slope…or calculate the difference of the X difference…between two pieces and Y difference between two pieces,…and see if those match.…And so, one way to express it is to say…we have a delta or a difference in X…and a variable, a delta or a difference in the Y values.…
And if those two are the same,…then they're equidistant vertically and horizontally,…and so, slope one,…and so, that's going to be a problem for us.…The two would be attacking each other…if they're on the same diagonal.…And so, we need to make that calculation.…Now, the tricky bit here is we need to do this…for multiple possible positions containing queens.…And so, we have to go across all of the elements…in our array.…So, for integer i equals one,…i less than, equal eight positions on the board,…
Skill Level Intermediate
1. Problem 1: Pond Oreille
2. Problem 2: Where Am I?
3. Problem 3: Eight Queens
4. Problem 4: Accessing Peripherals
5. Problem 5: Facial Recognition
6. Problem 6: Real-Time Information Dashboard
Next steps2m 46s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.