MathGroup Archive 2002

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

Search the Archive

Re: Finding pattern Matched series

  • To: mathgroup at smc.vnet.net
  • Subject: [mg33078] Re: [mg33051] Finding pattern Matched series
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Fri, 1 Mar 2002 06:51:33 -0500 (EST)
  • References: <200202270548.AAA18168@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Assuming I understood your problem correctly, how about

In[1]:=
T = {{1, 2}, {3, 4}, {2, 3}, {5, 6}, {4, 5}, {6, 4},
    {4, 1}};

In[2]:=
Cases[Flatten[Outer[List, T, T, 1], 1], {{_, x_}, {x_, _}}]
Out[2]=
{{{1,2},{2,3}},{{3,4},{4,5}},{{3,4},{4,1}},{{2,3},{3,4}},{{5,6},{6,4}},{{4,
      5},{5,6}},{{6,4},{4,5}},{{6,4},{4,1}},{{4,1},{1,2}}}

In[3]:=
Cases[Flatten[Outer[List, T, T, T, 1], 2],
  {{_, x_}, {x_, y_}, {y_, _}}]
Out[3]=
{{{1,2},{2,3},{3,4}},{{3,4},{4,5},{5,6}},{{3,4},{4,1},{1,2}},{{2,3},{3,4},{4
,
      5}},{{2,3},{3,4},{4,1}},{{5,6},{6,4},{4,5}},{{5,6},{6,4},{4,1}},{{4,

5},{5,6},{6,4}},{{6,4},{4,5},{5,6}},{{6,4},{4,1},{1,2}},{{4,1},{1,2},{2,
      3}}}

In[4]:=
Cases[Flatten[Outer[List, T, T, T, T, 1], 3],
  {{_, x_}, {x_, y_}, {y_, z_}, {z_, _}}]
Out[4]=
{{{1,2},{2,3},{3,4},{4,5}},{{1,2},{2,3},{3,4},{4,1}},{{3,4},{4,5},{5,6},{6,

4}},{{3,4},{4,1},{1,2},{2,3}},{{2,3},{3,4},{4,5},{5,6}},{{2,3},{3,4},{4,

1},{1,2}},{{5,6},{6,4},{4,5},{5,6}},{{5,6},{6,4},{4,1},{1,2}},{{4,5},{5,

6},{6,4},{4,5}},{{4,5},{5,6},{6,4},{4,1}},{{6,4},{4,5},{5,6},{6,4}},{{6,
      4},{4,1},{1,2},{2,3}},{{4,1},{1,2},{2,3},{3,4}}}

Tomas Garza
Mexico City

----- Original Message -----
From: "Jari Curty" <jabidof at yahoo.fr>
To: mathgroup at smc.vnet.net
Subject: [mg33078] [mg33051] Finding pattern Matched series


> Dear Mathgroup,
>
> Here is the problem:
>
> Given the following list T = {{1, 2}, {3, 4}, {2, 3}, {5, 6}, {4, 5}, {6,
> 4}, {4, 1}} extract ALL the series of the following form:
>
> {{#, x_}, {x_, #}}
> {{#, x_}, {x_, y_}, {y_, #}}
> {{#, x_}, {x_, y_}, {y_, z_}, {z_, #}}
> etc...
>
> for the for the value # in Range[Max[T]].
>
> I guess it is a subtle mixture between Patterns and Maps but I can see it
:-
> (
>
> Thanks for your appreciated help!
>
> Jari
>



  • Prev by Date: Re: Intersection[...,SameTest] ?
  • Next by Date: Re: Intersection[...,SameTest] ?
  • Previous by thread: Re: Finding pattern Matched series
  • Next by thread: MathLink and lists