Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fill(grid, old_value, new_value, seed):
- x = seed[0];
- y = seed[1];
- rows = len(grid);
- if rows <= 0:
- return;
- columns = len(grid[0]);
- if columns <= 0:
- return;
- nextX = (x - 1, x, x + 1);
- nextY = (y - 1, y, y + 1);
- for u in nextX:
- for v in nextY:
- if u < 0 or u >= rows or v < 0 or v >= columns:
- continue;
- if grid[u][v] == old_value:
- grid[u][v] = new_value;
- fill(grid, old_value, new_value, (u, v));
- def descendants(family_tree, name, distance):
- arr = [];
- if distance < 1 or name not in family_tree:
- return arr;
- for descendant in family_tree[name]:
- print(descendant);
- if distance == 1:
- arr.append(descendant);
- else:
- arr += descendants(family_tree, descendant, distance - 1);
- return arr;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement