Re: Please help, factorisation question
- To: mathgroup at smc.vnet.net
- Subject: [mg97317] Re: Please help, factorisation question
- From: Valeri Astanoff <astanoff at gmail.com>
- Date: Wed, 11 Mar 2009 04:20:03 -0500 (EST)
- References: <gp2bh5$92b$1@smc.vnet.net>
On 9 mar, 07:04, plzhlp <n... at live.be> wrote: > Hi all, > > first thanks very much to all who responded to my previous post. > > i am having trouble finding a way to do the following: > > i have a list of numbers P, and i need ask the question: which members of the set are products of other members and what are their factorisations by these other members. > > i notice there are graph/tree functions in mathematica to represent this sort of thing visually but im at a loss for how to implement them > > anyway for an example > > P = {a, b, c, d} > > OUTPUT: > > a -> c^2 * d > b -> c * d^2 > c -> c > d -> d Good day, Here is one possible solution using "Tuples" [it may not be very fast and... the output is not exactly what you wished ]: In[1]:= fac[numbers_List, oneNumber_Integer] := Module[{factors, factors2, factors3}, factors = {}; factors2 = Select[numbers, Divisible[oneNumber, #] &]; Do[factors3 = Select[Tuples[factors2, n], Times @@ # == oneNumber &]; If[factors3 == {}, Break[]]; factors = Join[factors, Union[Sort /@ factors3]], {n, 2, Length[factors2]}]; factors]; In[2]:= numbers = {2, 3, 6, 12, 5, 30, 10, 15, 11, 13}; In[3]:= {#, fac[numbers, #]} & /@ numbers Out[3]= {{2, {}}, {3, {}}, {6, {{2, 3}}}, {12, {{2, 6}, {2, 2, 3}}}, {5, {}}, {30, {{2, 15}, {3, 10}, {5, 6}, {2, 3, 5}}}, {10, {{2, 5}}}, {15, {{3, 5}}}, {11, {}}, {13, {}}} Thanks for an interesting exercise... V.Astanoff