-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
45 lines (41 loc) · 1.34 KB
/
functions.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def search_man(data, event):
num = 0
place = {}
for train in data:
for car in train['cars']:
num += 1
for man in car['people']:
if event.get('passenger') == man:
car['people'].remove(man)
place['num'] = num
place['name'] = train['name']
return place
if not place:
return -1
def replace_man(data, event, value):
destination = value['num'] + event.get('distance')
for train in data:
for car in train['cars']:
destination -= 1
if destination == 0 and value['name'] == train['name']:
car['people'].append(event.get('passenger'))
return 1
return -1
def switch(data, event):
value = event.get('cars')
train_from = event.get('train_from')
train_to = event.get('train_to')
if value > 0:
tail = []
for train in data:
if train['name'] == train_from:
for car in train['cars'][::-1]:
if value > 0:
train['cars'].remove(car)
value -= 1
tail.append(car)
for train in data:
if train['name'] == train_to:
train['cars'].extend(reversed(tail))
else:
return -1