2010年1月12日火曜日

チャレンジ

このエントリーをブックマークに追加 このエントリーを含むはてなブックマーク
人材獲得作戦・4 試験問題ほかの試験問題にチャレンジ
30分でLv2まで。おせー。 goalから小さくなるように逆にたどればいい気もしてきた。面倒だからもういいや。プログラミングコンテストに出る連中だと10分とかだろ。これ。

* * * * * * * * * * * * * * * * * * * * * * * * * *

* S * ( 7) * ( 9)(10)(11)(12)(13)(14)(15)(16)(17)(18)(19)(20)(21)(22)(23)(24)(25)(26)(27)(28) *

* ( 0) * ( 6) * ( 8)( 9) * (13)(14) * * * * * * * * * * * * * (28)(29) *

* ( 1) * ( 5)( 6)( 7) * (15)(14)(15)(16) * * * * * * * * * * * * (29)(30) *

* ( 2)( 3)( 4)( 5) * (17)(16)(15)(16)(17)(18)(19)(20)(21)(22)(23)(24)(25)(26)(27)(28)(29)(30)(31) *

* * * * * * * * * * * * * * (22) * * * * * * * * * * *

* (36)(35)(34)(33)(32)(31)(30)(29)(28)(27)(26)(25)(24)(23)(24)(25)(26)(27)(28)(29)(30)(31)(32)(33) *

* * (36) * * * * * * * * * * * * * * * * * * * * * * *

* (38)(37)(38)(39)(40)(41) * (45)(46)(47)(48)(49)(50)(51)(52)(53)(54)(55)(56)(57)(58) G (64)(65) *

* (39)(38) * (40)(41)(42)(43)(44)(45) * * * * * * * * * * * (59) * (63)(64) *

* (40)(39)(40)(41) * (43)(44)(45)(46)(47)(48)(49)(50) * * * * * * * (60) * (62)(63) *

* (41)(40)(41)(42)(43)(44)(45) * (47)(48)(49)(50)(51)(52)(53)(54)(55)(56)(57)(58)(59)(60)(61)(62) *

* * * * * * * * * * * * * * * * * * * * * * * * * *

コード

f = open('meiz')

m = []
for line in f:
cs = []
for c in line:
cs.append(c)
m.append(cs)

f.close()
print m


def locate_x(x, m):
for i, line in enumerate(m):
for j, c in enumerate(line):
if c==x:
return i, j
raise

print locate_x('S', m)
print locate_x('G', m)

def pretty(m):
for cs in m:
line = ''
for c in cs:
if isinstance(c, int):
line += '(%2i)'%c
else:
line += ' '+c+' '
print line


def clone(m):
r = []
for line in m:
cs = []
for c in line:
cs.append(c)
r.append(cs)
return r

def step(x, m, count):
V = m[x[0]][x[1]]
if isinstance(V, int):
if V <= count:
return False
m[x[0]][x[1]] = count
return search(x, m, count + 1)
if V == ' ':
m[x[0]][x[1]] = count
return search(x, m, count + 1)
elif V == 'G':
return True
elif V == 'S':
return False
elif V == '*':
return False
else:
pass
assert False

def search(S, m, count):
#print count ,S

# North
x = S[0] - 1, S[1]
step(x, m, count)
# South
x = S[0] + 1, S[1]
step(x, m, count)
# West
x = S[0], S[1] - 1
step(x, m, count)
# East
x = S[0], S[1] + 1
step(x, m, count)

search(locate_x('S', m), m, 0)
pretty(m)

0 件のコメント: