# Untitled

Apr 17th, 2021
881
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def fill(grid, old_value, new_value, seed):
2.     x = seed[0];
3.     y = seed[1];
4.
5.     rows = len(grid);
6.     if rows <= 0:
7.         return;
8.     columns = len(grid[0]);
9.     if columns <= 0:
10.         return;
11.
12.     nextX = (x - 1, x, x + 1);
13.     nextY = (y - 1, y, y + 1);
14.     for u in nextX:
15.         for v in nextY:
16.             if u < 0 or u >= rows or v < 0 or v >= columns:
17.                 continue;
18.
19.             if grid[u][v] == old_value:
20.                 grid[u][v] = new_value;
21.                 fill(grid, old_value, new_value, (u, v));
22.
23. def descendants(family_tree, name, distance):
24.     arr = [];
25.     if distance < 1 or name not in family_tree:
26.         return arr;
27.
28.     for descendant in family_tree[name]:
29.         print(descendant);
30.         if distance == 1:
31.             arr.append(descendant);
32.         else:
33.             arr += descendants(family_tree, descendant, distance - 1);
34.
35.     return arr;
36.
RAW Paste Data