Back-To-School Deals - hours only!Up to 80% off on all courses and bundles.-Close
Recap
Tuples as return types in functions
Tuples as records
List of tuples
Summary
16. Question 1

Instruction

Here comes question 1!

Exercise

Write a function count_near_positions() that takes two arguments:

  • checkers_positions – a list of all checker positions in a rectangle board during play (which are tuples (x, y)). Each tuple on the list corresponds to the consecutive checker's position during the game.
  • treasure_position – the position (as a tuple) of a treasure on that game board.

Calculate how many times the checker's distance from the treasure was less than 2 during a game and return the result in your function. Here's how you can count the distance between the treasure with coordinates (x_1, y_1) and the checker with coordinates (x_2, y_2):

distance =|x_1 - x_2| + |y_1 - y_2|

Stuck? Here's a hint!

In your code, use the following condition:

if abs(x1 - x2) + abs(y1 - y2) < 2: