现有题号称爱因斯坦出的智力题全世界只有2%能够做出。
------------------------------------------------
1、在一条街上,有5座房子,喷了5种颜色。
2、每个房里住着不同国籍的人
3、每个人喝不同的饮料,抽不同品牌的香烟,养不同的宠物
问题是:谁养鱼?
提示:
1、英国人住红色房子
2、瑞典人养狗
3、丹麦人喝茶
4、绿色房子在白色房子左面
5、绿色房子主人喝咖啡
6、抽Pall Mall 香烟的人养鸟
7、黄色房子主人抽Dunhill 香烟
8、住在中间房子的人喝牛奶
9、 挪威人住第一间房
10、抽Blends香烟的人住在养猫的人隔壁
11、养马的人住抽Dunhill 香烟的人隔壁
12、抽Blue Master的人喝啤酒
13、德国人抽Prince香烟
14、挪威人住蓝色房子隔壁
15、抽Blends香烟的人有一个喝水的邻居

为了便于消除翻译的误差,先将英文版本贴出:

Let us assume that there are five houses of different colors next to each other on the same road. In each house lives a man of a different nationality. Every man has his favorite drink, his favorite brand of cigarettes, and keeps pets of a particular kind.
  1. The Englishman lives in the red house.
  2. The Swede keeps dogs.
  3. The Dane drinks tea.
  4. The green house is just to the left of the white one.
  5. The owner of the green house drinks coffee.
  6. The Pall Mall smoker keeps birds.
  7. The owner of the yellow house smokes Dunhills.
  8. The man in the center house drinks milk.
  9. The Norwegian lives in the first house.
  10. The Blend smoker has a neighbor who keeps cats.
  11. The man who smokes Blue Masters drinks bier.
  12. The man who keeps horses lives next to the Dunhill smoker.
  13. The German smokes Prince.
  14. The Norwegian lives next to the blue house.
  15. The Blend smoker has a neighbor who drinks water.

The question to be answered is: Who keeps fish?

~

现在请你用c#写出解这个问题的程序!

相信不少人对此题的第一个想法是通过暴力算法穷举所有可能让计算机进行求解。如果是这样那么你不用辛苦了,下面早就有人这么干过了:
暴力算法解益智题(c#2.0版本):http://www.webasp.net/article/27/26094.htm
C#轻松解决世纪迷题 :http://tech.ccidnet.com/pub/article/c1081_a94061_p1.html
这些解法虽然都是对的,但是正如有人评论道:用笔解这题时候可比用程序看起来省力多了........算的上“轻松”吗?
在这里向大家隆重推荐香港城市大学计算机科学院的陈汉伟博士(Dr. Andy Chun, Hon Wai)的人工智能工具 NSolver
用NSolver如何解决问题?
先举一个简单的例子:
IQ 题:
    农场里有兔子和鸡若干只,知道共20个头和56条腿。问兔子和鸡各多少只?
用c#来解这个问题,可能是:

Einstein's Riddle 爱因斯坦出的智力题?using System;
Einstein's Riddle 爱因斯坦出的智力题?
public class Rabbit 
}

有什么不足?

    1、没有变量/未知量的概念
    2、没有什么值合法什么不合法的概念(问题域)
    3、没有变量间的关系/约束概念
    4、所有都Hardcode了,不能扩展到更复杂的问题
    5、暴力破解穷举

比较一下NSolver的解法:

Einstein's Riddle 爱因斯坦出的智力题?using ai.net.Solver;
Einstein's Riddle 爱因斯坦出的智力题?
using System;
Einstein's Riddle 爱因斯坦出的智力题?
public class Rabbit : Solver 
}


现在用NSolver解决爱因斯坦问题:

Einstein's Riddle 爱因斯坦出的智力题?using System;
Einstein's Riddle 爱因斯坦出的智力题?
using System.Text;
Einstein's Riddle 爱因斯坦出的智力题?
using ai.net.Solver;
Einstein's Riddle 爱因斯坦出的智力题?
using System.Diagnostics;
Einstein's Riddle 爱因斯坦出的智力题?
using System.Collections;
Einstein's Riddle 爱因斯坦出的智力题?
Einstein's Riddle 爱因斯坦出的智力题?
class Einstein : Solver
}


看看这一行行代码吧,多么简洁易懂! 现在你要做的就是陈述问题,NSolver帮你做剩下的!
延伸阅读
         
http://sc.info.gov.hk/gb/www.ugc.edu.hk/rgc/rgcnews9/Pages/6%20AI-C.html
NSolver的好处就是,它不仅仅能解决这个爱因斯坦的问题,它所能解决的是属于一个叫做“Constraint Satisfaction Problems”的一大堆问题。 
      我这里再给大家出个类似的题目,请你用NSolver来解决它:
 Our problem consists of three mice living next to each other in three holes in the wall. Each mouse has a favorite cheese flavor and a favorite TV show. Here are the hints:

  1. Mickey Mouse loves Gouda
  2. Mighty Mouse's favorite TV show is Emergency Room
  3. The mouse that lives in the left hole never misses an episode of Seinfeld
  4. Mickey Mouse and Mighty Mouse have one mouse hole between them
  5. The Simpsons fan does not live on the left of the Brie lover

相关文章: