Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
complex is better than complicated solution in Clear category for The Lantern Festival by veky
def lanterns_flow(river_map, minutes):
river = {j-i*1j for i, row in enumerate(river_map)
for j, cell in enumerate(row) if cell == "."}
edge = {z.real for z in river if not z.imag}
free, near = river - edge, (-1, 0, 1)
def stream(pos, way=-1j):
"Extract a stream from free (right wall algorithm)."
current = [pos]
while pos.imag > 1 - len(river_map):
for turn in near:
turned = way * 1j**turn
aim = pos + turned
if aim in free:
pos, way = aim, turned
free.remove(aim)
current.append(aim)
break
return current
lanterns = {stream(start)[minutes] for start in sorted(edge)}
lights = {z + x+y*1j for z in lanterns for x in near for y in near}
return len(lights & river)
Oct. 6, 2014
Comments: