🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.prolog
Article #32

Re: How to pick elements out of lists?

#32
From: Tim Menzies
Date: Sun, 01 Nov 1992 05:36
49 lines
2013 bytes
From article <1992Oct29.140104.7751@coli.uni-sb.de>, by ulma@coli.uni-sb.de (Ulrich Mayring):
> Hello netters, I have a problem:
> 
> I have a list and need to recursively pick two elements out of it. I need
> every pair of elements in every order, however the order of the pair itself
> is not important. It should also be possible to pick an element and the []
> as a pair, thus guaranteeing that in the end I will have every pair and
> every single element. Then I will test the pair (or single) and if it doesn't
> suit my purpose I want to go back into the recursion to get the next one.
> 
> 
> Thanx a lot if you can help,
> 
> 
>      Ulrich Mayring
> 
>        - Also wir waren mit grau eigentlich sehr zufrieden -     


% no substitute for simplicity, i always say...

twins(L,X) :- 	subset(L,X), (X = [_,_] | X = [_] | X = []).

subset([],[]).
subset([H|T],[H|REST]) :- subset(T,REST).
subset([H|T],REST) :- subset(T,REST).   
                                          
% twins([a,b,c],Twins)?
%
% Twins = [a, b]
% 
% Twins = [a, c]
% 
% Twins = [a]
% 
% Twins = [b, c]
%
% Twins = [b]
% 
% Twins = [c]
% 
% Twins = []

--
  ^       Tim Menzies (a 1/2 doctor)              | 
 /"\__/\  AI Lab, Computer Science, Uni. NSW      | "Scientific progress
*       \ P.O. Box 1, Kensington, Australia, 2033 |  goes 'BOINK' ? "
 \  _  _/ +61-2-663-4576 (fax) +61-2-697-3940 (w) |    -- Hobbes
  \| ""   timm@cs.unsw.oz.au                      |            
Technical Details
Message-ID: <1992Nov1.053612.7414@usage.csd.unsw.OZ.AU>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!usage!spectrum!timm
References: <1992Oct29.140104.7751@coli.uni-sb.de>

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.prolog
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!metro!usage!spectrum!timm
From: timm@spectrum.cs.unsw.oz.au (Tim Menzies)
Subject: Re: How to pick elements out of lists?
Message-ID: <1992Nov1.053612.7414@usage.csd.unsw.OZ.AU>
Sender: news@usage.csd.unsw.OZ.AU
Nntp-Posting-Host: sienna.spectrum.cs.unsw.oz.au
Reply-To: timm@spectrum.cs.unsw.oz.au (Tim Menzies)
Organization: none
References: <1992Oct29.140104.7751@coli.uni-sb.de>
Date: Sun, 1 Nov 1992 05:36:12 GMT
Lines: 50