English Translation

Mandatory task

International standard ISO-1234 for storing positions of obstacles on cycling pathways prescribes:

  • Each line of the file corresponds to a "line" of a cycling path.
  • The first number is the y coordinate, stored with three digits, with leading zeros. Coordinate 42 is written as 042.
  • This number if followed by colon.
  • This is followed by pairs of number representing the starting and ending x-coordinates of obstacles. Numbers are separated by -. Each number is padded (with spaces) to 4 places, where the first number is aligned to the right and the second to the left.

In practice, obstacles

{4: [(5, 6), (9, 11)],
 5: [(9, 11), (19, 20), (30, 34)],
 13: [(5, 8), (9, 11), (17, 19), (22, 25), (90, 100)]}

are stored as

004:   5-6      9-11
005:   9-11    19-20    30-34
013:   5-8      9-11    17-19    22-25    90-100

Write a function zapisi_ovire(filename, obstacles), which stores the given obstacles into the file with the given name. Obstacles are given as dictionaries whose keys are y-coordinates, and the corresponding values are lists of pairs that represent the starting and ending x-coordinates of obstacles. See an example above.

Tests will use a different file name every time (in practice - the current time). It the test is successful, it will remove the file, otherwise it will keep it so that you can inspect the result of your function.

Optional task

The department for economy and motorized traffic is proud of its inventions. (They, for instance, promote the "shared space on Slovenska cesta", where cyclists can practice slalom in between buses going in opposite directions, as an innovation on a worldwide scale. Which it undoubtedly is.)

As a part of this homework, they introduced a new format for storing positions of obstacles. Their standard MOL-666 stores the above obstacles as:

4
5
6
9
11

5
9
11
19
20
30
34

13
5
8
9
11
17
19
22
25
90
100

169
1
2

According to MOL's advertising material, the new standard is intended to promote cycling and sustainable mobility, while at the same time contributing to achieving climate neutrality via low-carbon society.

Write a function preberi_ovire(filename), which reads the data from the given file into a dictionary like the one above.

Tests will prepare a file named "ovire.txt", but your function should not assume that name. The file name is given as an argument.

Zadnja sprememba: četrtek, 15. december 2022, 13.44