海归网首页   海归宣言   导航   博客   广告位价格  
海归论坛首页 会员列表 
收 藏 夹 
论坛帮助 
登录 | 登录并检查站内短信 | 个人设置 论坛首页 |  排行榜  |  在线私聊 |  专题 | 版规 | 搜索  | RSS  | 注册 | 活动日历
主题: 提上来,回答悠悠小草 [每日一题] 之 谁养鱼?
回复主题   printer-friendly view    海归论坛首页 -> 海归茶馆           焦点讨论 | 精华区 | 嘉宾沙龙 | 白领丽人沙龙
  阅读上一个主题 :: 阅读下一个主题
作者 提上来,回答悠悠小草 [每日一题] 之 谁养鱼?   
所跟贴 提上来,回答悠悠小草 [每日一题] 之 谁养鱼? -- 游客 - (3932 Byte) 2005-4-19 周二, 01:47 (1481 reads)
wanyan




头衔: 海归中校

头衔: 海归中校
声望: 学员
性别: 性别:男
加入时间: 2004/02/20
文章: 254
来自: Texas, USA
海归分: 44966





文章标题: here's a program that give answer in one second: (362 reads)      时间: 2005-4-19 周二, 14:36   

作者: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









相关主题
提上来,回答木辛大侠(断断续续歇了几天) 海归主坛 2014-1-03 周五, 21:37
提上来,回答【波儿的波】女人的身材怎么才叫好看?(原创照片)【美股图】 海归茶馆 2005-10-01 周六, 19:40
提上来,回答日资企业的报酬问题 海归论坛 2003-8-15 周五, 19:16
提上来,回答日资的报酬问题 海归论坛 2003-8-15 周五, 18:33
[问题回答]提上来答关于跃民的"gambling是否有trick... 海归酒吧 2006-10-09 周一, 01:25
[转帖]弟子提问 师父回答(二) 生活风情 2016-2-13 周六, 13:52
[转帖]弟子提问 师父回答(一) 生活风情 2016-2-09 周二, 12:01
忙里偷闲,回答兼声明兼感谢 海归酒吧 2009-3-23 周一, 16:14

返回顶端
阅读会员资料 wanyan离线  发送站内短信
显示文章:     
回复主题   printer-friendly view    海归论坛首页 -> 海归茶馆           焦点讨论 | 精华区 | 嘉宾沙龙 | 白领丽人沙龙 所有的时间均为 北京时间


 
论坛转跳:   
不能在本论坛发表新主题, 不能回复主题, 不能编辑自己的文章, 不能删除自己的文章, 不能发表投票, 您 不可以 发表活动帖子在本论坛, 不能添加附件不能下载文件, 
   热门标签 更多...
   论坛精华荟萃 更多...
   博客热门文章 更多...


海归网二次开发,based on phpbb
Copyright © 2005-2026 Haiguinet.com. All rights reserved.