2023-11-09 20:58:58 +00:00
|
|
|
import itertools
|
|
|
|
|
|
|
|
def koordinate(s):
|
|
|
|
(start, *dolzina) = s.split("-")
|
|
|
|
return (int(start), int(start) + len(dolzina) - 1)
|
|
|
|
|
|
|
|
def vrstica(s):
|
2023-11-16 15:18:51 +00:00
|
|
|
(stev, *ovire) = s.split()
|
2023-11-09 20:58:58 +00:00
|
|
|
return list(map(lambda ovira: (*koordinate(ovira), int(stev[1:-1])), ovire))
|
|
|
|
|
|
|
|
def preberi(s):
|
|
|
|
return list(itertools.chain(*map(vrstica, s.splitlines())))
|
|
|
|
|
|
|
|
def intervali(s):
|
|
|
|
return list(map(lambda x: str(x[0]) + "-" * (x[1] - x[0] + 1), s))
|
|
|
|
|
|
|
|
def zapisi_vrstico(y, xs):
|
|
|
|
return " ".join(["(" + str(y) + ")", *intervali(xs)])
|
|
|
|
|
|
|
|
def zapisi(ovire):
|
|
|
|
return "\n".join(map(lambda a: zapisi_vrstico(a[0], map(lambda b: (b[0], b[1]), sorted(a[1]))), itertools.groupby(sorted(ovire, key=lambda x: x[2]), lambda x: x[2])))
|