The task contains tests. The task is considered solved only if it passes all the tests. Check the instructions for running the tests..

The City Municipality (MOL) has sent a map of obstacles on the bike path. The map is stored as a list of strings, representing "rows": # represents an obstacle, and . represents a clear path. A typical example of a correctly secured bike path is:

map = [
    "......",
    "..##..",
    ".##.#.",
    "...###",
    "###.##",
]

All strings are of equal length.

Write the following functions:

  1. dolzina_ovir(vrstica) receives one row, for example, ".##.####...##.", and returns the total length of obstacles, that is, the number of # characters (in this case, 8).
  2. stevilo_ovir(vrstica) receives a row and returns the number of obstacles in the row. For the example above, it should return 3, as there is one double obstacle, one quadruple obstacle, and another double obstacle, totaling three.
  3. najdaljsa_ovira(vrstica) returns the length of the longest obstacle. In the example above, it is 4.
  4. pretvori_vrstico(vrstica) returns a list of pairs (x0, x1) representing the starts and ends of obstacles. For the example above, it returns [(2, 3), (5, 8), (12, 13)]. Note that columns are numbered from 1, not 0.
  5. pretvori_zemljevid(vrstice) receives the entire map as seen in the task's introduction and returns a list of triplets (x0, x1, y) representing obstacles. For the example map, it should return [(3, 4, 2), (2, 3, 3), (5, 5, 3), (4, 6, 4), (1, 3, 5), (5, 6, 5)]. The list should be sorted by rows and within each row, by columns, just like in the example. Note that rows are also numbered from 1, not 0.
  6. izboljsave(prej, potem) receives two maps - one is older, and the other is newer. The function should return a list of newly placed obstacles. This list should also be sorted by rows and within each row, by columns. You can assume that MOL does not remove existing obstacles but only adds new ones. Additionally, no obstacle is "expanded"; new obstacles are not placed directly to the left or right of existing ones. You can also assume that the new bike path is not wider. (Or narrower; it has the same shape.)
  7. huligani(previous, current); sometimes, vandals remove some of the obstacles on the bike path, endangering the safety of cyclists. Therefore, obstacles not only appear but also disappear. The function huligani should return two lists: one containing all the new obstacles and the other containing all the removed obstacles.
Последнее изменение: суббота, 21 октября 2023, 18:08