Newsgroups: comp.ai
Path: cantaloupe.srv.cs.cmu.edu!rochester!udel!nntp.sunbelt.net!news.sprintlink.net!howland.reston.ans.net!Germany.EU.net!zib-berlin.de!irz401!news.tu-chemnitz.de!fauern!cs.tu-berlin.de!informatik.uni-bremen.de!nordwest.pop.de!news.hamburg.pop.de!news.gun.de!news.xenologics.com!localhost!dinkla
From: Joern Dinkla <dinkla@informatik.uni-bonn.de>
Subject: Re: Riddle to solve: Safe combination
In-Reply-To: <3pseha$6ne@toves.cs.city.ac.uk>
X-Sender: dinkla@localhost
Content-Type: TEXT/PLAIN; charset=US-ASCII
Message-ID: <Pine.LNX.3.91.950524185630.2900B-100000@localhost>
Sender: news@edina.xenologics.com
Organization: Xenologics - Networks + Communications GmbH
References: <3pqc0t$e22@p235.informatik.uni-Bremen.de> <3pr03c$5or@netnews.upenn.edu> <3pseha$6ne@toves.cs.city.ac.uk>
Mime-Version: 1.0
Date: Wed, 24 May 1995 17:09:19 GMT
Lines: 56

On 23 May 1995, Michael Jampel wrote:

> 
> I agree.
> 
> But I dislike Screamer code (just because I am ignorant of Lisp), so
> here is an Eclipse version. It took less than 10 minutes to write, and
> much less than a second to run.
> 
> (A total of 26 lines of code, if you agree with my layout conventions.)
> 

And here is the solution in Goedel. Although it took quite long (ca. one minute)
on a vanilla 486DX2-66 with only 8MB, the code is IMHO beautiful.

------------------------------ cut here ------------------------------
MODULE		Safe.

IMPORT		Integers, Lists.

PREDICATE	Constraints : List(Integer).

Constraints([d1,d2,d3,d4,d5,d6,d7,d8,d9]) <-
	d1 ~= 1 & d2 ~= 2 & d3 ~= 3 & d4 ~= 4 &
	d5 ~= 5 & d6 ~= 6 & d7 ~= 7 & d8 ~= 8 & d9 ~= 9 &
	d7 = d4 - d6 &
	d2 + d6 = d3 + d7 &
	d1 * d2 * d3 = d8 + d9.

PREDICATE	Safe : List(Integer).

Safe(list) <-
	Constraints(list) &
	Permutation([1,2,3,4,5,6,7,8,9], list).		
------------------------------ cut here ------------------------------

and here is the output:

----------------------------------------------------------------------
[Safe] <- Safe(sol).

sol = [5,3,1,6,9,2,4,7,8] ? ;

sol = [7,1,2,9,3,5,4,6,8] ? ;
No
[Safe] <- 
----------------------------------------------------------------------

Regards,

	Joern

Joern Dinkla, Zuelpicher Strasse 56, 50674 Koeln, FRG	    
dinkla@cs.uni-bonn.de	               +49-221-421723        


