diff --git a/09_kontrola/naloga.py b/09_kontrola/naloga.py index 710c930..3d30f31 100644 --- a/09_kontrola/naloga.py +++ b/09_kontrola/naloga.py @@ -156,14 +156,13 @@ def najboljsa_cetrt(a: int, zemljevid: list[str]): def dosegljive(x, y, max_d, max_n, zemljevid): def dosegljive_r(x, y, n, prepovedani): + if zemljevid[y][x] == "*": n = max_n else: - if n == 0: - return set() prepovedani.add((x, y)) - points = set() + prepovedani = prepovedani.copy() accessible = set() for d in range(1, max_d + 1): @@ -182,7 +181,13 @@ def dosegljive(x, y, max_d, max_n, zemljevid): ry_inc = -1 ry += ry_inc - points.update(accessible) + if n == 0: + if any(zemljevid[y][x] == "*" for x, y in accessible): + accessible = {(x, y) for x, y in accessible if zemljevid[y][x] == "*"} + else: + return set() + + points = set(accessible) for x, y in accessible: points.update(dosegljive_r(x, y, n - 1, prepovedani)) return points