While doing some work-related stuff this afternoon, I maintained a
conversation with my friend Erwin on Jabber, and he sent me a link to
href="http://www.wiwi-treff.de/home/index.php?mainkatid=5&ukatid=5&sid=505&artikelid=490&pagenr=1">[DE]
Einstein’s riddle(
href="http://www.manbottle.com/trivia/Einstein_s_Riddle.htm">[EN]).
Upon reading it, I decided that this was the long-awaited opportunity to
finally write a useful prolog program!
Some six hours later, I knew a lot more about prolog and had a nice
[DE]
solution to the riddle. Now, most people claim they can manually do
it in under an hour, but I still feel cool…
themel@sophokles:~$ gprolog –init-goal “consult(‘einstein.prolog’)”
compiling /home/themel/einstein.prolog for byte code…
/home/themel/einstein.prolog:20 warning: singleton variables [L] for rightof/3
/home/themel/einstein.prolog:21 warning: singleton variables [Z] for rightof/3
/home/themel/einstein.prolog compiled, 60 lines read – 4840 bytes written, 18 ms
GNU Prolog 1.2.18
By Daniel Diaz
Copyright (C) 1999-2004 Daniel Diaz
| ?- solution(X).
X =
[
house(1,norway,dunhill,yellow,cat,water),
house(2,denmark,marlboro,blue,horse,tea),
house(3,britain,pallmall,red,bird,milk),
house(4,german,rothmans,green,_,coffee),
house(5,sweden,winfield,white,dog,beer)
]
? ;
(2 ms) no
| ?-
The cool thing is that a prolog solution allows you to toy with the rule
set and find out lots of thing that are not so easy with pen and paper -
what if we remove hint number 4? What if we make the danish guy like
beer? What if ‘the first house’ is actually the rightmost one because
we’re reading Arabic (thanks, Erwin!)?
Even though prolog is fun, it’s definitely mind-boggling – I wouldn’t
have gotten all that far if I hadn’t stumbled across some similar
samples on the web. Definitely the worst intro to prolog is what I found
on
href="http://www.kuro5hin.org/story/2004/2/25/124713/784">kuro5hin…


No Comments
Be the first to comment!