Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Pattern matching more than once

Hi Asari,

I hope I understood what you are interested in.


With[{li2=Cases[li1,{y,__}]},If[li2=={},{x,y}, extent[{x,y},#]&/@li2]];


fu[li1_,li2_]:=  Module[{li3=Intersection[li1,li2],aux},


aux doubles the common elements and then splits (with UnsameQ) between
those elements, producing segments with ends where crossing can take
place. FixedPoint extents---beginning with the first segments of the
two lists---until there is no more extension possible.

I supposed you were interested in all possible  chains, not only the
maximal ones.


-----Original Message-----
From: ASARI Hirotsugu <> To:
Subject: [mg12060] [mg11991] Pattern matching more than once

>I have been stuck with the following problem for about 10 days.  I can't
>think of an elegant solution.
>Input: Two lists, from some universal set Output: Many "spliced" lists
>obtained from the input.
>e.g. {{a,b,c},{d,e,f}} --> {{a,b,c},{d,e,f}} (no common element)
> {{a,b,c},{d,b,f}} --> {{a,b,c},{d,b,f},{a,b,f},{d,b,c}}
> {{a,b,c,d,e},{f,b,g,d,h}} -->
> {{a,b,c,d,e},{a,b,c,d,h},{a,b,g,d,e},{a,b,g,d,h},
> {f,b,c,d,e},{f,b,c,d,h},{f,b,g,d,e},{f,b,g,d,h}}
>I will regard the input as list of chains (totally ordered set) coming
>from a partially ordered set, and I would like to extend these chains
>as much as possible.  If there is at most one common element in the
>inputs, the following will do:
> {list1,list2,{pre1,x,post2},{pre2,x,post1}};
>The problem is that when the lists have more than one common element,
>the second common element will not be considered at all.  I suppose I
>could just write, for instance,
> list2:{pre2___,x_,mid2___,y_,post2___}}]:=
> Union[
> {list1,{pre1,x,mid1,y,post2},{pre1,x,mid2,y,post1},
> {pre1,x,mid2,y,post2},list2,{pre2,x,mid1,y,post1},
> {pre2,x,mid1,y,post2},{pre2,x,mid2,y,post1}}]; But this is very ugly.
>I suppose I could write some For[] loop through
>Intersection[list1,list2], but I would rather avoid it if I could.
>Any help would be appreciated.
>ASARI Hirotsugu                 //
>finger://   //    ph://
> "We are what we pretend to be, so we must be careful
> about what we pretend to be." --Kurt Vonnegut

  • Prev by Date: Very odd behaviour in Mod/N
  • Next by Date: Re: Re: how to compute pi by using continued fraction?
  • Prev by thread: Re: Pattern matching more than once
  • Next by thread: Re: Pattern matching more than once