Introduction
Designing a circuit board with only two layers can be tricky because you need to connect many parts without wires crossing. The challenge is to find paths for all connections while using just the top and bottom layers.
Imagine a two-story house where you need to run wires from switches to lights without crossing wires on the same floor. You can run wires on the first floor going left to right and on the second floor going front to back, using stairs (vias) to switch floors when needed.
┌───────────────┐ ┌───────────────┐ │ Top Layer │──────▶│ Horizontal │ │ (Traces run │ │ traces │ │ left-right) │ └───────────────┘ │ │ │ ┌─────┐ │ ┌───────────────┐ │ │Via │────▶│ │ Vertical │ │ └─────┘ │ │ traces on │ │ Bottom Layer │──────▶│ bottom layer │ │ (Traces run │ └───────────────┘ │ up-down) │ └───────────────┘
via(top_layer, bottom_layer) uses via(top_layer, bottom_layer) which is the standard and syntactically correct format.routes = [
{"start": "A", "end": "B", "layer": "top"},
{"start": "B", "end": "C", "layer": "bottom"},
{"start": "C", "end": "D", "layer": "top"}
]
vias = [route for route in routes if route["layer"] != routes[routes.index(route)-1]["layer"]]
print(len(vias))routes = [
{"start": "X", "end": "Y", "layer": "top"},
{"start": "Y", "end": "Z", "layer": "bottom"}
]
vias = [route for i, route in enumerate(routes) if route["layer"] != routes[i-1]["layer"]]
print(len(vias))
What is the cause of the error?Pass the test and this pattern moves unknown