Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Toothpicks by kazuki.h
def toothpicks(step):
result, edges, points, switch = 1, {(1, 0), (-1, 0)}, {(0, 0)}, False
while step > 1:
points |= edges
new_edges, discard_edges = set(), set()
for (px, py) in edges:
for q in [(px+switch, py+(not switch)), (px-switch, py-(not switch))]:
if q in points: pass
elif q in new_edges: discard_edges.add(q)
else: new_edges.add(q)
new_edges -= discard_edges
step -= 1
result += len(edges)
edges = new_edges
points |= discard_edges
switch = not switch
return result
March 28, 2023
Comments: