Archipelago

Archipelago

Moderate+
DE English FR PL UK ZH-HANS

Did you know, that Stockholm is a city built on 14 islands, connected by 57 bridges over the two waters Lake Mälaren and the Baltic Sea.

You are given a rectangular map of islands where the number in each island tells how many bridges are connected to it.

example

The object is to connect all islands according to the number of bridges with the following rules:

  • there are no more than two bridges in the same direction;
  • bridges can only be vertical or horizontal and can't cross islands or other bridges;
  • when completed, all island on a map are interconnected by bridges, enabling passage from any island to another.

Your function must return a sorted ascending tuple of directions with bridges. Each direction is a tuple itself with three integers. The first two are serial numbers of islands (sorted ascending), the third one is number of bridges between these two islands (1 or 2). Islands must be ordered starting from 1, from top-left to bottom-right, row-major.

example

Input: Tuple of tuples of integers (int).

Output: Tuple of tuples of three integers (int).

Examples:

assert archipelago(
    (
        (0, 1, 0, 0, 2),
        (2, 0, 0, 2, 0),
        (0, 0, 2, 0, 2),
        (0, 0, 0, 1, 0),
        (3, 0, 6, 0, 3),
    )
) == (
    (1, 2, 1),
    (2, 6, 1),
    (3, 4, 1),
    (3, 8, 1),
    (4, 7, 1),
    (5, 9, 2),
    (6, 10, 1),
    (8, 9, 2),
    (9, 10, 2),
)  # very easy, 5x5
assert archipelago(
    (
        (3, 0, 6, 0, 3),
        (0, 1, 0, 0, 0),
        (2, 0, 2, 0, 0),
        (0, 2, 0, 0, 3),
        (5, 0, 3, 0, 0),
        (0, 0, 0, 0, 1),
        (2, 0, 1, 0, 0),
    )
) == (
    (1, 2, 2),
    (1, 5, 1),
    (2, 3, 2),
    (2, 6, 2),
    (3, 8, 1),
    (4, 7, 1),
    (5, 9, 1),
    (7, 8, 1),
    (8, 11, 1),
    (9, 10, 2),
    (9, 12, 2),
    (10, 13, 1),
)  # very easy, 5x7
assert archipelago(
    (
        (0, 2, 0, 0, 2, 0),
        (2, 0, 2, 0, 0, 0),
        (0, 1, 0, 0, 0, 2),
        (5, 0, 8, 0, 3, 0),
        (0, 0, 0, 0, 0, 0),
        (1, 0, 3, 0, 0, 3),
    )
) == (
    (1, 2, 1),
    (1, 5, 1),
    (2, 9, 1),
    (3, 7, 2),
    (4, 8, 2),
    (6, 12, 2),
    (7, 8, 2),
    (7, 10, 1),
    (8, 9, 2),
    (8, 11, 2),
    (11, 12, 1),
)  # very easy, 6x6

Precondition:

  • all tests are solvable and have one solution.

This mission is an implementation of the following Hashi Google Play app. All tests are the first ones from their kinds (difficulty and dimensions). I strongly recommend you to use the app to understand the mission better and solve it easier as I did while creating it.

Settings
Code:
Other:
Invalid hot key. Each hot key should be unique and valid
Hot keys:
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.

Pair Programming (Beta-version)

Welcome to Pair Programming! Engage in real-time collaboration on coding projects by starting a session and sharing the provided unique URL with friends or colleagues. This feature is perfect for joint project development, debugging, or learning new skills together. Simply click 'Start Session' to begin your collaborative coding journey!

Waiting for Pair Programming to start...

You are trying to join a pair programming session that has not started yet.

Please wait for the session creator to join.

Waiting for Pair Programming to reconnect...

It looks like the creator of the pair programming session closed the editor window.

It might happen accidentally, so that you can wait for reconnection.

×
 
 
<< <
> >>
exec show

Whats Next?

Free accounts will see Best CheckiO solutions with some delay.
Best Solutions will be opened in a moment
Become Awesome and Don't wait
The next stage is ""
Will be activated in
View More Solutions Random Review Solutions Go to the next mission