MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: All Factors of a number

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53049] Re: [mg53025] All Factors of a number
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 21 Dec 2004 05:19:39 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

A shorter method than my first response:

Needs["DiscreteMath`Combinatorica`"];

bt=Table[KSubsets[{1,2,3,5},a],{a,3}];

Times@@@#&/@bt

{{1, 2, 3, 5}, {2, 3, 5, 6, 10, 15}, {6, 10, 15, 30}}


Bob Hanlon

> 
> From: Bob Hanlon <hanlonr at cox.net>
To: mathgroup at smc.vnet.net
> Date: 2004/12/20 Mon PM 07:52:19 EST
> To: "Ulrich Sondermann" <usondermann at earthlink.net>, 
<mathgroup at smc.vnet.net>
> Subject: [mg53049] Re: [mg53025] All Factors of a number
> 
> Needs["DiscreteMath`Combinatorica`"];
> 
> bt=Table[KSubsets[{1,2,3,5},a],{a,3}];
> 
> ((Times@@#)&/@#)&/@bt
> 
> {{1, 2, 3, 5}, {2, 3, 5, 6, 10, 15}, {6, 10, 15, 30}}
> 
> 
> Bob Hanlon
> 
> > 
> > From: "Ulrich Sondermann" <usondermann at earthlink.net>
To: mathgroup at smc.vnet.net
> > To: mathgroup at smc.vnet.net
> > Subject: [mg53049] [mg53025] All Factors of a number
> > 
> > Following is a test code that I am trying to get down to a set of
> > instructions that will allways put all of the factors of a number in a table
> > or list.
> > bt contains all of the factors if I multiply each list entry, however I
> > cannot accomplish that with a single line, as an example I have broken 
into
> > the three lists needed for this example. The results of each "Times@@" is
> > what I am after all placed into one table. All of my attempts have proved
> > disasterous, I am new to Mathematica and could do this with nested 
loops 
> in
> > any programming language, but this has me stumped.
> > Thanx!
> > 
> > <<DiscreteMath`Combinatorica`
> > bt=Table[KSubsets[{1,2,3,5},a],{a,3}]
> > {{{1},{2},{3},{5}},{{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}},{{1,2,3},{1,2,5},{1
> > ,3,5},{2,3,5}}}
> > bt1=bt[[1,All]]
> > {{1},{2},{3},{5}}
> >  Table[Times@@bt1[[a]],{a,4}]
> > {1,2,3,5}
> > bt2=bt[[2,All]]
> > {{1,2},{1,3},{1,5},{2,3},{2,5},{3,5}}
> > Table[Times@@bt2[[a]],{a,6}]
> > {2,3,5,6,10,15}
> > bt3=bt[[3,All]]
> > {{1,2,3},{1,2,5},{1,3,5},{2,3,5}}
> > Table[Times@@bt3[[a]],{a,4}]
> > {6,10,15,30}
> > 
> > 
> 

Bob Hanlon
Chantilly, VA


  • Prev by Date: Re: please solve [LinearAlgebra]
  • Next by Date: Re: Primes (again)
  • Previous by thread: Re: All Factors of a number
  • Next by thread: UnitStep bugs remain in ver. 5.01