-
Notifications
You must be signed in to change notification settings - Fork 0
/
treasure_hunts.py
76 lines (58 loc) · 1.41 KB
/
treasure_hunts.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# encoding: utf-8
#! /usr/bin/env python
import re
import turtle
MAP = """
+-------------------------+
¦ 34 ¦ 21 ¦ 32 ¦ 41 ¦ 25 ¦
+----+----+----+----+-----¦
¦ 14 ¦ 42 ¦ 43 ¦ 14 ¦ 31 ¦
+----+----+----+----+-----¦
¦ 54 ¦ 45 ¦ 52 ¦ 42 ¦ 23 ¦
+----+----+----+----+-----¦
¦ 33 ¦ 15 ¦ 51 ¦ 31 ¦ 35 ¦
+----+----+----+----+-----¦
¦ 21 ¦ 52 ¦ 33 ¦ 13 ¦ 23 ¦
+-------------------------+
"""
def map2list(tmap):
lis = []
for line in str.split(tmap, "\n"):
clues = [clue for clue in re.findall("[0-9]+", line)]
if len(clues) != 0:
lis.append(clues)
return lis
def next_clue(clue, lis):
x = int(clue[0])
y = int(clue[1])
return lis[x - 1][y - 1]
def search_treasre(lis):
clue = "11"
route = ["11"]
while clue != next_clue(clue, lis):
clue = next_clue(clue, lis)
route.append(clue)
return route
def draw_route(route):
res = "\n"
ind = 0
for rou in route:
if ind >= 4:
ind = 0
res += "=>" + rou + "\n"
else:
ind += 1
res += "=>" + rou
print res
def report_map(lis):
print "\n"
for row in lis:
line = "|"
for col in row:
line += " " + str(col) + " " + "|"
print line
if __name__ == "__main__":
lis = map2list(MAP)
route = search_treasre(lis)
report_map(lis)
draw_route(route)