Supply Line Supply Line
Moderate
English

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 .

Example:

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

examples

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) .

Precondition:

  • 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

Settings
Code:
CheckiO Extensions

CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.

In order to install CheckiO client you'll need installed Python (version at least 3.8)

Install CheckiO Client first:

pip3 install checkio_client

Configure your tool

checkio --domain=py config --key=

Sync solutions into your local folder

checkio sync

(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)

checkio serv -d

Alternatevly, you can install Chrome extension or FF addon

checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium

Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.

×
 
 
<< <
> >>
exec

Whats Next?

Free accounts will see Best CheckiO solutions with some delay.
Best Solutions will be opened in
Become Awesome and Don't wait
The next stage is ""
Will be activated in
View More Solutions Random Review Solutions Share your own solution
Go to the next mission Back to the list of missions Back to the map