aboutsummaryrefslogtreecommitdiff
path: root/challenge-129/lubos-kolouch/python/ch-1.py
blob: bb4f2633ae1c270e3a8efc1aebb5cb8bb8053296 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python
# -*- coding: utf-8 -*-

tree = {1: [2, 3], 3: [4], 4: [5, 6]}


def distance(node, root, dist):
    if root == node:
        return dist
    if root in tree:
        for child in tree[root]:
            d = distance(node, child, dist + 1)
            if d is not None:
                return d


print(distance(6, 1, 0))
print(distance(5, 1, 0))
print(distance(2, 1, 0))
print(distance(4, 1, 0))