Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Berserk Rook by Moff
def find_path(rook, opposites):
max_path = []
moves = []
for p in (0, 1):
res = sorted([rook] + [op for op in opposites if rook[p] == op[p]],
key=lambda x: x[1-p])
i = res.index(rook)
if i > 0:
moves.append(res[i - 1])
if i < len(res) - 1:
moves.append((res[i + 1]))
for op in moves:
if any(a == b for a, b in zip(rook, op)):
path = find_path(op, set(r for r in opposites if r != op))
if len(path) > len(max_path):
max_path = path
return [rook] + max_path
def berserk_rook(rook, opposite):
return len(find_path(rook, opposite)) - 1
Aug. 10, 2015