English translation
We received a map of obstacles. It is stored as a list of strings representing the "rows": #
denotes an obstacle, and .
are free spaces.
Last week we wrote a program that processes lists of obstacles given as triplets (x0, x1, y)
, so we need to translate the map into this form.
Warm-up task
Write a program that begins with description of obstacles in a single row, for instance
ovire = ".##..####...##"
The program must output a list of pairs representing the starting and ending "columns" of obstacles. For the above setup, the expected outcome is [(2, 3), (6, 9), (13, 14)]
. Note that coordinates are not "pythonic": the first column is marked as 1 (not 0) and the last column is included. (6, 9)
also includes column 9 and thus spans over 4 columns.
You must test your program at least on those two strings:
- ".##..####...##"
prints [(2, 3), (6, 9), (13, 15)]
- ##..#...#
prints [(1, 2), (5, 5), (9, 9)]
.
Mandatory task
Write a program that starts with the entire map and prints a list of obstacles in the format we're used to from the last week. It the map is
zemljevid = [
"......",
"..##..",
".##.#.",
"...###",
"###.##",
]
the program must print [(3, 4, 2), (2, 3, 3), (5, 5, 3), (4, 6, 4), (1, 3, 5), (5, 6, 5)]
.
Note that the first line is 1
, not 2
.
Extra task
Write a program that gets a list of obstacles and prints out a map.
Put this into the same file as the mandatory task. You can just convert the same list back.