skills/tabular/toroidal-manhattan-distance/SKILL.md
Compute shortest Manhattan distance on a toroidal (wrapping) grid by comparing normal vs wrap-around routes in each axis
npx skillsauth add wenmin-wu/ds-skills tabular-toroidal-manhattan-distanceInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
On a toroidal grid (edges wrap around), the shortest path between two points may go through the boundary. For each axis, compare the direct distance with the wrap-around distance and take the minimum. This is essential for pathfinding, nearest-neighbor search, and feature engineering on any game or simulation with periodic boundary conditions.
def toroidal_manhattan(x1, y1, x2, y2, size):
"""Shortest Manhattan distance on a size x size wrapping grid."""
dx = abs(x1 - x2)
dy = abs(y1 - y2)
dx = min(dx, size - dx)
dy = min(dy, size - dy)
return dx + dy
def toroidal_direction(from_pos, to_pos, size):
"""Best direction to move toward target on toroidal grid."""
dx = (to_pos[0] - from_pos[0]) % size
dy = (to_pos[1] - from_pos[1]) % size
best = None
if dx != 0:
best = 'EAST' if dx <= size // 2 else 'WEST'
if dy != 0:
d = 'NORTH' if dy <= size // 2 else 'SOUTH'
best = d if best is None else best
return best
dist = toroidal_manhattan(3, 18, 19, 2, size=21) # wraps in both axes
size - diff (wrap-around route)sqrt(dx² + dy²) for Euclidean distancedata-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF