Article View: comp.lang.prolog
Article #4218Prolog Brain Teaser
From: duncan
Date: Tue, 20 Feb 1990 18:27
Date: Tue, 20 Feb 1990 18:27
25 lines
1189 bytes
1189 bytes
With apologies to the many readers who will be familiar with
this little Prolog Puzzle which came to my notice some time ago.
I thought it was worth posting. It has (to me at least) a pleasing but
non-obvious solution. Here goes!
You are given the standard definition of append/3
append( [], L, L).
append( [H|T], L, [H|T1]):- append( T, L, T1).
which can be used reversibly to append two lists and to generate sublists.
The problem is this. Using this definition, define append/4 which will
append 3 lists to form a 4th *AND* will work reversibly to generate all
sublist solutions without looping on backtracking.
There are four obvious definitions but only one of them works. Try to
solve it first without testing on a Prolog system.
Have fun.
Duncan Lowes
P.S. Before I get flamed this is not my homework :-) :-)
Technical Details
Message-ID:
<5091.25e18bfa@mva.cs.liv.ac.uk>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!mucs!liv-cs!duncanShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!mucs!liv-cs!duncan From: duncan@mva.cs.liv.ac.uk Newsgroups: comp.lang.prolog Subject: Prolog Brain Teaser Message-ID: <5091.25e18bfa@mva.cs.liv.ac.uk> Date: 20 Feb 90 18:27:06 GMT Organization: Computer Science CSMVAX, Liverpool University Lines: 25