aboutsummaryrefslogtreecommitdiff
path: root/tanken.py
blob: 501978bb57a00f2c93822a7197b216ad42a13880 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/env python3

def tanken(drives, cost):
    passagers = {}
    distance = 0.
    drives = [d.split(' ') for d in drives]

    for d in drives:
        try:
            distance += int(d[0])
        except:
            return None, "Lines have to start with the driven distance!"
        for p in d[1:]:
            if p not in passagers:
                passagers[p] = [int(d[0]),0]
            else:
                passagers[p][0] += int(d[0])
   
    c = cost/distance 

    for d in drives:
        c_d = c * int(d[0]) / (len(d) - 1)
        for p in d[1:]:
            passagers[p][1] += c_d

    return passagers, None