Re: Element Extraction
- To: mathgroup at smc.vnet.net
- Subject: [mg19257] Re: Element Extraction
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Thu, 12 Aug 1999 01:24:17 -0400
- References: <7or50k$141@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Kew, someList = {{0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 1, 0}, {0, 1, 1}, {0, 1, 2}, {0, 2, 0}, {0, 2, 1}, {0, 2, 2}, {1, 0, 0}, {1, 0, 1}, {1, 0, 2}, {1, 1, 0}, {1, 1, 1}, {1, 1, 2}, {1, 2, 0}, {1, 2, 1}, {1, 2, 2}, {2, 0, 0}, {2, 0, 1}, {2, 0, 2}, {2, 1, 0}, {2, 1, 1}, {2, 1, 2}, {2, 2, 0}, {2, 2, 1}, {2, 2, 2}}; target = {0, 0, 1}; Cases[someList, x_ /; Count[MapThread[SameQ, {target, x}], False] <= 1] {{0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 1, 1}, {0, 2, 1}, {1, 0, 1}, {2, 0, 1}} Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 Kew Joinery <kewjoi at hixnet.co.za> wrote in message news:7or50k$141 at smc.vnet.net... > Hello everyone, > I have a problem extracting list of list. > Given some list, consisting of elements (not all of them distinct) with > the same length and some "target" list of the same length, for example: > In[26]:= > someList={{0,0,0},{0,0,1},{0,0,2},{0,1,0},{0,1,1},{0,1,2},{0,2,0},{0,2,1},{0 , > > > > 2,2},{1,0,0},{1,0,1},{1,0,2},{1,1,0},{1,1,1},{1,1,2},{1,2,0},{1,2,1},{1, > > > > 2,2},{2,0,0},{2,0,1},{2,0,2},{2,1,0},{2,1,1},{2,1,2},{2,2,0},{2,2,1},{2, > > 2,2}}; > > In[27]:= > target={0,0,1}; > > Hamming distance between two bit strings means the number of bit > positions in which they differ. For example consecutive elements of the > Gray code list have Hamming distance = 1. > I need to extract these cases(elements of someList) which differ from > target in one coordinate (Hamming distance = 1) or less (the > element===target itself//Hamming distance=0), so the answer should be: > > In[33]:= > answer={{0,0,0},{0,0,1},{0,0,2},{0,1,1},{0,2,1},{1,0,1},{2,0,1}}; > > How could I achieve the extraction efficiently? > Thank you in advance for any suggestions. > Eugene > > > > >