Universal search across Courses, Lessons, Skills, Projects, Challenges, Competitions, Jobs, Internships, and Users
•
1
2
3
4
5
6
7
8
9
10
Module 1: Informed State Space Search & A*•Lesson 2
1.2 Manhattan Distance Heuristic in Grid Worlds
### Manhattan Distance In grid environments where diagonal movements are disallowed, the Manhattan distance between $(x_1, y_1)$ and $(x_2, y_2)$ is: $$h(n) = |x_1 - x_2| + |y_1 - y_2|$$
Python 3.11
•
Interactive Challenge
+95 XP
Challenge Objective
Calculate the Manhattan heuristic from (0,0) to (4,3) and output 'H_COST: 7'.
solution.py
UTF-84 SpacesAuto-saved
cpython3.11:~/workspace
CPython 3.11.8 (WASM)
$python3 -u solution.py
Click "Compile & Run" (or press Ctrl + Enter) to compile AST, verify bytecode, and execute the solution.