Re: Find Upper Neighbor in a list
- To: mathgroup at smc.vnet.net
- Subject: [mg85070] Re: Find Upper Neighbor in a list
- From: P_ter <peter_van_summeren at yahoo.co.uk>
- Date: Sun, 27 Jan 2008 05:42:33 -0500 (EST)
Hello Oleksandr Pavlyk, first of all: thanks for looking at my problem. However, there are many more loops than 2: every Cases is a loop, also Subsets is a loop, FixedPoint is a loop. Count them! But it is good to discuss. I have this basislist el. I made a small module: lengthPositions[basis_] := Module[{lengthList}, lengthList = Length[#] & /@ basis; {#[[1]], Position[lengthList, #[[1]], 1, #[[2]]][[All, 1]]} & /@ Tally @ lengthList ] Here there is the loop Tally. But in Position I already use the results of Tally, that is, the number that a list with a certain length appears in the basislist. Position does only the job needed. I now get: {{1, {1, 2, 3, 4}}, {2, {5, 6, 7, 8, 9}}, {3, {10, 11, 12, 13}}, {4, {14, 15}}, {5, {16, 17}}, {8, {18}}} You are right in order by partial inclusion. That means that if I have a certain set e.g., {5,6} I am sure that any list of length 3 which contains {5,6,x_}/; x_>6 is a next upper neighbor. I only need to search for the sets of length 3 and I know where they are from the above. But also, any set which has a length larger than 3 and contains a 1, or 2, or 3, or 4 or all is such a next upper neighbor ("before 5"). Such a select is also of limited intent. I do not know how to formulate that. I now use too many loops (which work, but I do not like that). What I learn from your solution is that I must use patterns. And the use of Subset is also nice. But I would like to have less loops. If possible. with friendly greetings, P_ter