@@ -0,0 +1,1475 @@
+from compiler.ast import flatten%0A%0A%0Adef findFirstTarget(grid):%0A    for i, line in enumerate(grid):%0A        for j, point in enumerate(line):%0A            if pointIsTarget(point):%0A                return %5Bj, i%5D%0A    return %5B-1, -1%5D%0A%0A%0Adef findSecondTarget(grid, offsetX, row):%0A    for j, point in enumerate(grid%5Brow%5D%5BoffsetX:%5D):%0A        if pointIsTarget(point):%0A            return %5BoffsetX + j, row%5D%0A    return %5B-1, -1%5D%0A%0A%0Adef findThirdTarget(grid, col, offsetY):%0A    for i, line in enumerate(grid%5BoffsetY:%5D):%0A        if pointIsTarget(line%5Bcol%5D):%0A            return %5Bcol, offsetY + i%5D%0A    return %5B-1, -1%5D%0A%0A%0Adef pointIsTarget(point):%0A    return point == '0'%0A%0A%0Adef strToLst(string):%0A    lst = %5B%5D%0A    for c in string:%0A        lst.append(c)%0A    return lst%0A%0A%0Adef gridHasNode(grid):%0A    return '0' in ''.join(flatten(grid))%0A%0A%0Adef solve(grid):%0A    while gridHasNode(grid):%0A        x1, y1 = findFirstTarget(grid)%0A        x2, y2 = findSecondTarget(grid, x1 + 1, y1)%0A        x3, y3 = findThirdTarget(grid, x1, y1 + 1)%0A        # Three coordinates: a node, its right neighbor, its bottom neighbor%0A        print '%25i %25i %25i %25i %25i %25i' %25 (x1, y1, x2, y2, x3, y3)%0A        # Remove the first node, and try another time%0A        grid%5By1%5D%5Bx1%5D = '.'%0A%0A# The number of cells on the X axis%0Awidth = int(raw_input())%0A# The number of cells on the Y axis%0Aheight = int(raw_input())%0A%0Agrid = %5B%5D%0Afor i in xrange(height):%0A    # Width characters, each either 0 or .%0A    grid.append(strToLst(raw_input()))%0A%0A%0Asolve(grid)%0A

Add exercise APU