Article View: comp.lang.prolog
Article #3181Re: Programming Quickie
From: Stephen Knight
Date: Mon, 28 Mar 1988 13:03
Date: Mon, 28 Mar 1988 13:03
22 lines
1035 bytes
1035 bytes
Dear Ian,
Here is my solution, which I submit for elegance points ...
exactly_one( X, Y ) :-
X contains Y, /* contains is infix in my version */
p( Y ),
forall(
( X contains Y1, Y /= Y1 ),
q( Y1 )
).
forall( X, Y ) :- not( (X, not(Y)) ).
The inefficiency of this programs is the repeated calculation of q( Term ).
One approach would be to patch this by making "q" cache, but other solutions
on this problem are more efficient than that anyway.
Steve Knight
PS: I have tested this on some simple examples, although I could have introduced
errors in transcribing it to this message.
Technical Details
Message-ID:
<1600012@otter.hple.hp.com>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mailrus!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!otter!sfkReferences:
<1600011@otter.hple.hp.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!mailrus!ames!ucsd!sdcsvax!ucsdhub!hp-sdd!hplabs!otter!sfk From: sfk@otter.hple.hp.com (Stephen Knight) Newsgroups: comp.lang.prolog Subject: Re: Programming Quickie Message-ID: <1600012@otter.hple.hp.com> Date: 28 Mar 88 13:03:51 GMT References: <1600011@otter.hple.hp.com> Organization: Hewlett-Packard Laboratories, Bristol, UK. Lines: 22