Start at (0,0). 5km East: (5,0). Turn right (now facing South), walk 12km: (5,-12). Turn right again (now facing West), walk 5km: (0,-12). Distance from start = √[(0-0)² + (-12-0)²] = 12km
Advanced Shortcut: For rectangular paths, if you return to same X or Y coordinate, the distance equals the remaining coordinate value.
In example 2, X-coordinate returned to 0, so distance = Y-coordinate = 12km