The Lantern Festival

The Lantern Festival


Tōrō nagashi (灯籠流し) is a Japanese ceremony in which participants float paper lanterns (chōchin) down a river. The word tōrō is Japanese for lantern, while nagashi means "to cruise" or "flow". This is primarily done on the last evening of the Bon Festival, a festival based on the belief that these lanterns would guide the spirits back to the world of the dead.

Our robots are going to float their own illuminated lanterns down a river and watch how they flow down the river. Rivers in RoboLand generally have flat banks, sharp right angle turns and a consistent width throughout the length of the river.

Each Robot simultaneously put their lantern in a row spanning the entire width of the river. Each lantern floats with a constant speed of 1 cell/minute. The river has several streams and each lantern will float in its own stream without moving into any of the other streams. The image below illustrates how streams flow in the river.


The river flows from the northern to the southern edge. It is not intersected by nor does it merge with another river, or a branch of itself. Because the river has the same width, streams do not intersect each other. The river always has banks and does not end or touch west or east edge of the map.

The Robots place their lanterns on the northern edge of river. This moment occurrs at the 0th minute. The number of lanterns is equal to the width of the river (in cells). Each lantern lights all the neighbouring cells, including the diagonal cells. You should model how the lanterns flow down the river and determine how many water cells will be lit at a time interval of X minutes.

You are given a map detailing a section of the river as a sequence of strings which forms a matrix. Water cells are marked as ".", land cells - "X". In addition, you are given a specified time as a number of minutes from when the lanterns are placed. Count how many water cells will be lit at that given time. If a cell is lit by two lanterns at the same time, then count it only once. Don't forget to count cells where the lanterns are located.

lantern-examples lantern-examples

Input: Two arguments. A map of river as a tuple of strings and time as an integer.

Output: The number of lightened water cells as an integer.


               "XXX....X"), 0) == 8

How it is used: Here we will examine a complex model of parallel motion. This concept can be used to model the flow of a production line in a factory, or racecars over the course of a race track.

0 < len(river_map) < 20
The river has the same width in cells.
"time" is given for cases when all lanterns on the map.

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