Monday, November 17, 2008

script question

I think i asked before, but i am not sure. is there a way to get rid of redundant lines? I don't think there is but i figure i should throw it out there.


Thread[First[#]®Last[#]]&/@Partition[Range[6100],5,1,1];
NestList[Round[Last[#]/10]->First[#]*10&/@#&,%,4];
GraphPlot[Flatten[%]]


Refering to script above:
second question would be about how i would connect different parts of a tupple set(i.e. {1,2,3,4}) at different points instead of just first to last. such as First#->Last#->Third#.

i still haven't figured that part out.

thanks,
Jean Pierre

1 comment:

Matt Howard said...

Yes, Union eliminates all duplicate instances in a list of objects. Here's a snippet for you to implement.

In[19]:= yourGraph = {{1 -> 2}, {1 -> 2}, {2 -> 1}, {3 -> 4}, {5 ->
6}};

In[26]:= {First[#[[1]]], Last[#[[1]]]} & /@ yourGraph
Union[Union[%, SameTest -> (#1 == Reverse[#2] &)]]
First[#] -> Last[#] & /@ %

Out[26]= {{1, 2}, {1, 2}, {2, 1}, {3, 4}, {5, 6}}

Out[27]= {{1, 2}, {3, 4}, {5, 6}}

Out[28]= {1 -> 2, 3 -> 4, 5 -> 6}

In plain words, convert the rules back in to lists of numbers eg 1->2 is {1,2} (Out[26]), then use Union twice. The first time to pick up duplicate cases, eg 1->2 and 1->2. The second to pick up reversed duplicates, eg. 1->2,2->1 (Out[27]). Once this is done, we put all the rules back together. (Out[28])