2024(6): clean before fix

This commit is contained in:
2024-12-26 11:41:21 +01:00
parent 1a7f6304ee
commit 9c65de6772
2 changed files with 19 additions and 21 deletions

View File

@ -18,11 +18,25 @@ if __name__ == "__main__":
m = Map()
#m.load_map("testinput")
m.load_map("input")
loop_obstacles = []
while m.step():
# After each step, we can fork the map and add the obstacle.
print(m.pos, m.direction)
if verbose:
print(m.pos, m.direction)
# Create a copy
forked_map = m.copy()
forked_map.map[forked_map.next_pos()] = Map.Tiles.OBSTACLE.value
print(f"Forking at {forked_map.next_pos()}... ", end="")
try:
while forked_map.step():
continue
except Map.LoopException:
print("loop.")
loop_obstacles.append(m.next_pos())
else:
print("no loop.")
#m.show()
print(len(m.trace), m.trace)
print(len(set(m.trace)))
#print(len(m.trace), m.trace)
#print(len(set(m.trace)))
print(len(loop_obstacles))