30
Last seen 2 years ago
Member for 9 years, 9 months, 26 days
Difficulty Normal
Too many nested loops. Poor reading.
Lines 32-33:
for dx, dy in ((0, -1), (0, 1), (-1, 0), (1, 0)):
px, py = x + dx, y + dy
do it more clearly:
for x, y in ((x, y-1), (x, y+1), (x-1, y), (x+1, y)):
More
def minimum(data):
ms = list(set([x[0] for x in data]))
check = []
for m in ms:
if all(d.find(m) <= 0 for d in data):
check.append(m)
return min(check)
I think here it will be a little bit shorter and clearer;))
I like your solution.
More
if all(color[i] != c for i in connect[n] if i < n):
^^^^^^^^
This is a smart way to get back to the original state. Nice!
More
Great! Discarding loops is very effective and sufficient for this kind of graphs.
More
if 0 <= field[i][j] < 9:
I think there is no need to check empty cells: field[i][j] == 0. You waste your time;) They have never got 'unknown' surrounding cells.
More
Lines 36-37 must be:
new_snake = (point,) + snake[:-1]
if new_snake not in closed:
More
I forgot one line before a cycle, but it isn't critical.
field[first[0]][first[1]] = -1
More
This is not a stable algorithm. Just one of the uses of "scanner memory card".
More
one-string code will be long and unreadable:
return min(abs(sum(data) - 2*sum(kit)) for kit in
(kit for i in range(1, len(data)//2+2) for kit in combinations(data, i)))
More
Read this comments:
[http://www.checkio.org/mission/boolean-algebra/publications/theholy7/python-3/hard-way/#comments](http://www.checkio.org/mission/boolean-algebra/publications/theholy7/python-3/hard-way/#comments)
More