Supply Line Supply Line

Many war games have rules concerning the supply lines. Units that can’t contact the supply source face a lot of troubles.

You should find the shortest supply line with Python.

The map used in this mission is a hex grid with a maximum size of 12x9 where each hex is numbered from A1 to L9. (A - L indicate a column, and 1 - 9 indicate a row.)

The map

You are given three arguments: the first is the position of your uint (a string), the second is the supply depots (the set of strings), and the third is the enemy units (the set of strings). You should return the minimum number of steps from your unit to the supply depot. If you can’t set a supply line at all, return None.

The effect of the enemy hex and its adjacent hexes:

  • You can’t lay the supply lines on these hexes.
    • If your unit is adjacent to the enemy’s, there is no problem with the supply line.
  • The supply depot on these hexes can’t be used .


supply_line('B4', {'F4'}, {'D4'}) == 6
supply_line('A3', {'A9', 'F5', 'G8'}, {'B3', 'G6'}) == 11


Input: Three arguments. The first one is the position of your unit as a string, the second one is the supply depots as the set of strings, the third one is the enemy units as the set of strings.

Output: The minimum number of steps from your unit to the supply depot as an integer (or None).

How it is used:
In war games. Searching for a path is important for movement and getting supplies. And the idea of the adjacent hex cells is often seen as a Zone of control(ZOC).


  • all(map(lambda x: re.match('[A-L][1-9]$', x), {you} | depots | enemies))
  • you not in depots | enemies
  • len(depots) > 0
  • len(enemies) ≥ 0