昨天报纸上看到个有趣的逻辑推理题,爱因斯坦声称世界上只有2%的人能解出:
- 有五个具有五种不同颜色的房间排成一排;
- 每个房间里分别住着一个不同国籍的人;
- 每个人都在喝一种特定品牌的饮料,抽一特定品牌的烟,养一特定的宠物;
- 没有任意两个人在抽相同品牌的香烟,或喝相同品牌的饮料,或养相同的宠物。
问题:谁在养鱼作为宠物?
爱因斯坦给出如下线索:
- 英国人住在红色的房子里;
- 瑞典人养狗作为宠物;
- 丹麦人喝茶;
- 绿房子紧挨着白房子,在白房子的左边;
- 绿房子的主人喝咖啡;
- 抽Pall Mall牌香烟的人养鸟;
- 黄色房子里的人抽Dunhill牌香烟;
- 住在中间那个房子里的人喝牛奶;
- 挪威人住在第一个房子里面;
- 抽Blends牌香烟的人和养猫的人相邻;
- 养马的人和抽Dunhill牌香烟的人相邻;
- 抽BlueMaster牌香烟的人和啤酒;
- 德国人抽Prince牌香烟;
- 挪威人和住在蓝房子的人相邻;
- 抽Blends牌香烟的人和喝矿泉水的人相邻。
在http://www.codeproject.com/cpp/Einstein.asp上有人用C++编出一个exe,在我Celeron 2.4G的机器上运行时间基本为0.002秒。可惜偶不懂C++,看不懂他的思路……是该安排时间好好学学真正面向对象的语言了。下载C++的源代码。
Einstein's riddle
- There are 5 houses in five different colors in a row.
- In each house lives a person with a different nationality.
- These five owners drink a certain type of beverage, smoke a certain brand of cigar and keep a certain pet.
- No owners have the same pet, smoke the same brand of cigar or drink the same beverage.
The question is: Who owns the fish?
Einstein's hints
- The Brit lives in the red house.
- The Swede keeps dogs as pets.
- The Dane drinks tea.
- The green house is on the immediate left of the white house.
- The green house's owner drinks coffee.
- The person who smokes Pall Mall rears birds.
- The owner of the yellow house smokes Dunhill.
- The man living in the center house drinks milk.
- The Norwegian lives in the first house.
- The man who smokes Blends lives next to the one who keeps cats.
- The man who keeps horses lives next to the man who smokes Dunhill.
- The owner who smokes BlueMaster drinks beer.
- The German smokes Prince.
- The Norwegian lives next to the blue house.
- The man who smokes Blends has a neighbor who drinks water.