🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #4223

Re: Prolog Brain Teaser

#4223
From: Cooperate
Date: Fri, 23 Feb 1990 19:45
28 lines
1567 bytes
In article <5091.25e18bfa@mva.cs.liv.ac.uk>, duncan@mva.cs.liv.ac.uk writes:
> 
>   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.
> 

Here is my solution ...

append([],L,L).
append([H|T],L,[H|T1]) :- append(T,L,T1).

app4([],[],L,L).
app4([],[H|T],L1,[H|T1]) :- append(T,L1,T1).
app4([H|T],L1,L2,[H|T1]) :- app4(T,L1,L2,T1).

First, narrow it down to two lists, then use regular append.
Also works in generation of sublists recursively. Note that 
on the second clause, an [H|T] notation was used for the second
argument in order to disable binding to an empty list and
therefore duplicating results on sublists.

Boris Pelakh				"Software - a spell one casts on a
pelakh@cerc.wvu.wvnet.edu		 computer to transform input into
coop@cerc.wvu.wvnet.edu			 errors."        -- Me

Disclaimer :    If my employer knew what I did with the time I get paid for,
		I would be out of a job. Let's keep this between us, OK ?
Technical Details
Message-ID: <399@cerc.wvu.wvnet.edu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!rochester!udel!haven!h.cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!hawksnest!coop
References: <5091.25e18bfa@mva.cs.liv.ac.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!pt.cs.cmu.edu!rochester!udel!haven!h.cs.wvu.wvnet.edu!cerc.wvu.wvnet.edu!hawksnest!coop
From: coop@hawksnest.cerc.wvu.wvnet.edu (Cooperate)
Newsgroups: comp.lang.prolog
Subject: Re: Prolog Brain Teaser
Summary: Solution ...
Message-ID: <399@cerc.wvu.wvnet.edu.edu>
Date: 23 Feb 90 19:45:10 GMT
References: <5091.25e18bfa@mva.cs.liv.ac.uk>
Sender: news@cerc.wvu.wvnet.edu
Lines: 28