Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #8497
| From | Dana DeLouis <dana01@me.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Getting stuck with finding an elegant solution without global variables |
| Date | 2012-02-12 10:06 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jh82vt$ol6$1@smc.vnet.net> (permalink) |
> I am trying to find an elegant solution, i.e. without a global
> variable to the following problem:
> Branch[Elem_, List_] := Elem + Cases[List, Except[Elem]]
>
> The the result would be {{3, 4, 5}, {3, 5, 6}, {4, 5, 7}, {5, 6, 7}}
Hi. Don't know if this would be of help.
Branch[v_List] := Map[Function[a, a + Cases[v, Except[a]]] , v]
Branch[{1,2,3,4}]
{{3,4,5}, {3,5,6}, {4,5,7}, {5,6,7}}
Your use of the function Except may not work well if there are duplicates in the list.
= = = = = = = = = = = = = =
HTH :>)
Dana DeLouis
Mac, Mathematica 8
= = = = = = = = = = = = = =
On Feb 7, 4:08 am, Fredob <fredrik.dob...@gmail.com> wrote:
> Hi,
>
> I am trying to find an elegant solution, i.e. without a global
> variable to the following problem:
>
> Given a list, e.g. {1,2,3,4}, create a new list where each element is
> a function of the "i th" element and the rest of the list, e.g.
>
> Branch[Elem_, List_] := Elem + Cases[List, Except[Elem]]
>
> The the result would be {{3, 4, 5}, {3, 5, 6}, {4, 5, 7}, {5, 6, 7}}
>
> I have used Map[f, List] but then I have to use a global variable in f
> to access the list itself, e.g. BranchG[Elem_] := Elem + Cases[List,
> Except[Elem]]
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Getting stuck with finding an elegant solution without global variables Dana DeLouis <dana01@me.com> - 2012-02-12 10:06 +0000
csiph-web