| 作者 |
提上来,回答悠悠小草 [每日一题] 之 谁养鱼? |
 |
| 所跟贴 |
提上来,回答悠悠小草 [每日一题] 之 谁养鱼? -- 游客 - (3932 Byte) 2005-4-19 周二, 01:47 (1482 reads) |
wanyan


头衔: 海归中校 声望: 学员 性别:  加入时间: 2004/02/20 文章: 254 来自: Texas, USA 海归分: 44966
|
|
作者:wanyan 在 海归茶馆 发贴, 来自【海归网】 http://www.haiguinet.com
result:
house 1: norway, yellow, water, cat, dunhill
house 2: denmark, blue, tea, horse, mix
house 3: english, red, milk, bird, pall mall
house 4: german, green, coffee, fish, prince
house 5: swidish, white, beer, dog, blue master
house 1: norway, yellow, water, cat, dunhill
house 2: denmark, blue, tea, horse, mix
house 3: english, red, milk, bird, pall mall
house 4: swidish, white, beer, dog, blue master
house 5: german, green, coffee, fish, prince
so german has the fish
--------------------------------------------------------
def recper(seq):
lenseq = len(seq)
if lenseq==2:
return [seq,[seq[1],seq[0]]]
newseq=[]
for i in range(lenseq):
subseq = recper(seq[:i]+seq[i+1:])
for c in subseq:
newseq.append([seq[i]]+c)
return newseq
#########################################################
#people
people=('english','norway','denmark','german','swidish')
#we already know norway live in first house #9
peoplelist = [[1]+a for a in recper([0,2,3,4])]
#########################################################
#color
color=('red','green','yellow','blue','white')
#we know 2nd house is blue #14
colorlist = [[a[0]]+[3]+a[1:] for a in recper([0,1,2,4])]
pc=[[p,c] for p in peoplelist for c in colorlist]
del peoplelist,colorlist
#green and white adjacent #4
#2nd is blue, then green and white must be in 2,3,4(3rd,4th,5th)
newlist=[]
for i in [2,3,4]: newlist += [p for p in pc if (p[1][i]==1 and p[1][i-1]==4) or (i<4 and p[1][i]==1 and p[1][i+1]==4)]
pc=[]
for i in [1,2,3,4]: pc += [p for p in newlist if p[0][i]==0 and p[1][i]==0]
#########################################################
#drink
drink=('coffee','tea','water','beer','milk')
#the one in the middle drink milk #8
drinklist = [a[:2]+[4]+a[2:] for a in recper([0,1,2,3])]
pcd=[[p[0],p[1],d] for p in pc for d in drinklist]
del pc,drinklist
#denmark drink tea
newlist=[]
for i in [0,1,3,4]: newlist += [p for p in pcd if p[0][i]==2 and p[2][i]==1]
#green drink coffe
pcd=[]
for i in [0,1,3,4]: pcd += [p for p in newlist if p[1][i]==1 and p[2][i]==0]
#########################################################
#pet
pet=('dog','horse','bird','cat','fish')
petlist = recper([0,1,2,3,4])
pcdp=[[p[0],p[1],p[2],d] for p in pcd for d in petlist]
del pcd,petlist
newlist=[]
for i in [1,2,3,4]: newlist += [p for p in pcdp if p[0][i]==4 and p[3][i]==0]
pcdp=newlist
#########################################################
#cigarite
smoke=('pall mall','dunhill','blue master','prince','mix')
smokelist = recper([0,1,2,3,4])
pcdps = [[p[0],p[1],p[2],p[3],d] for p in pcdp for d in smokelist]
del pcdp,smokelist
list1=[]
for i in [0,1,2,3,4]: list1 += [p for p in pcdps if p[4][i]==0 and p[3][i]==2]
del pcdps
list2=[]
for i in [0,1,2,3,4]: list2 += [p for p in list1 if p[4][i]==1 and p[1][i]==2]
del list1
list3=[]
for i in [0,1,2,3,4]: list3 += [p for p in list2 if p[4][i]==4 and ((i<4 and p[3][i+1]==3) or (i>0 and p[3][i-1]==3))]
del list2
list4=[]
for i in [0,1,2,3,4]: list4 += [p for p in list3 if p[4][i]==1 and ((i<4 and p[3][i+1]==1) or (i>0 and p[3][i-1]==1))]
del list3
list5=[]
for i in [0,1,2,3,4]: list5 += [p for p in list4 if p[4][i]==2 and p[2][i]==3]
del list4
list6=[]
for i in [0,1,2,3,4]: list6 += [p for p in list5 if p[4][i]==3 and p[0][i]==3]
del list5
final=[]
for i in [0,1,2,3,4]: final += [p for p in list6 if p[4][i]==4 and ((i<4 and p[2][i+1]==2) or (i>0 and p[2][i-1]==2))]
del list6
for var in final:
print
for i in [0,1,2,3,4]:
print " house %d: %s, %s, %s, %s, %s" % ( i+1, people[var[0][i]], color[var[1][i]], drink[var[2][i]], pet[var[3][i]], smoke[var[4][i]])
作者:wanyan 在 海归茶馆 发贴, 来自【海归网】 http://www.haiguinet.com
|
|
|
| 返回顶端 |
|
 |
|
-
提上来,回答悠悠小草 [每日一题] 之 谁养鱼? -- 书生 - (3932 Byte) 2005-4-19 周二, 01:47 (1482 reads) - here's a program that give answer in one second: -- wanyan - (4064 Byte) 2005-4-19 周二, 14:36 (363 reads)
|
|
|
|
您不能在本论坛发表新主题, 不能回复主题, 不能编辑自己的文章, 不能删除自己的文章, 不能发表投票, 您 不可以 发表活动帖子在本论坛, 不能添加附件不能下载文件, |
|
|