Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #88789

Re: find all multiplicands and multipliers for a number

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.071
X-Spam-Evidence '*H*': 0.86; '*S*': 0.00; 'root': 0.05; 'see:': 0.07; 'calculating': 0.09; 'item.': 0.09; 'name?': 0.09; 'subject:number': 0.09; 'def': 0.12; '(3,': 0.16; '(9,': 0.16; '3)]': 0.16; '999': 0.16; 'division,': 0.16; 'function?': 0.16; 'integer.': 0.16; 'inverse': 0.16; 'output?': 0.16; 'reversing': 0.16; 'subject:skip:m 10': 0.16; 'superfluous': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'written': 0.21; 'input': 0.22; 'header:User-Agent:1': 0.23; 'stopping': 0.24; '---': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'url:wiki': 0.31; 'decimal': 0.31; 'exclude': 0.31; 'there.': 0.32; 'subject:all': 0.32; "i'd": 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'done': 0.36; 'next': 0.36; 'possible': 0.36; 'url:org': 0.36; 'should': 0.36; 'list': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'dave': 0.60; 'most': 0.60; 'break': 0.61; 'numbers': 0.61; "you'll": 0.62; "you've": 0.63; 'real': 0.63; 'soon': 0.63; 'more': 0.64; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; 'prime': 0.74; 'repeat': 0.74; 'square': 0.74; 'gain': 0.79; 'divide': 0.84; 'end.': 0.84; 'factors,': 0.84; 'improvement': 0.84; 'multiplying': 0.84; 'received:74.208.4.194': 0.84; 'subject:find': 0.84; 'angel': 0.91; 'items,': 0.91; 'factors': 0.97
Date Fri, 10 Apr 2015 21:16:57 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: find all multiplicands and multipliers for a number
References <890bd388-f50a-4dec-9ef5-27715427472a@googlegroups.com> <55287387.4070501@davea.name>
In-Reply-To <55287387.4070501@davea.name>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V03:K0:/kzdUfqu8XKMaxg2MAgcYzMc1APh7bzp/ITTqaRfXXJM7D2d8om DjMJHpYL0Pqc3N8JvcND5b3ECUq3A3hom9Sk+0wBG6KHJ8o2pWo2PX7ScxsgAdD9ccNGaC2 VEWfoFBS1QbYCYwmr/KmOmlFkoY20DkBm6Wzrx3fmXVIW0sv3xzFtYa9Au8Rk2khp+Tp3DK Fml0vGVyz5EGNDQ2omV4Q==
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.210.1428715027.12925.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1428715027 news.xs4all.nl 2847 [2001:888:2000:d::a6]:42926
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:88789

Show key headers only | View raw


On 04/10/2015 09:06 PM, Dave Angel wrote:
> On 04/10/2015 07:37 PM, ravas wrote:
>> def m_and_m(dividend):
>>      rlist = []
>>      dm = divmod
>>      end = (dividend // 2) + 1
>>      for divisor in range(1, end):
>>          q, r = dm(dividend, divisor)
>>          if r is 0:
>>              rlist.append((divisor, q))
>>      return rlist
>>
>> print(m_and_m(999))
>> ---
>> output: [(1, 999), (3, 333), (9, 111), (27, 37), (37, 27), (111, 9),
>> (333, 3)]
>> ---
>>
>> How do we describe this function?
>> Does it have an established name?
>> What would you call it?
>> Does 'Rosetta Code' have it or something that uses it?
>> Can it be written to be more efficient?
>> What is the most efficient way to exclude the superfluous inverse tuples?
>> Can it be written for decimal numbers as input and/or output?
>>
>> Thank you!
>>
>
> I'd call those factors of the original number.  For completeness, I'd
> include (999,1) at the end.
>
> If it were my problem, I'd be looking for only prime factors.  Then if
> someone wanted all the factors, they could derive them from the primes,
> by multiplying all possible combinations.
>
> The program can be sped up most obviously by stopping as soon as you get
> a tuple where divisor > q.  At that point, you can just repeat all the
> items, reversing divisor and q for each item.  Of course, now I notice
> you want to eliminate them.  So just break out of the loop when divisor
>  > q.
>
> You can gain some more speed by calculating the square root of the
> dividend, and stopping when you get there.
>
> But the real place to get improvement is to only divide by primes,
> rather than every possible integer.  And once you've done the division,
> let q be the next value for dividend.  So you'll get a list like
>
> [3, 3, 3, 37]
>
> for the value 999
>
> See:
> http://rosettacode.org/wiki/Factors_of_an_integer#Python
>
>
And

http://rosettacode.org/wiki/Prime_decomposition#Python

There the function that you should grok is  decompose()

-- 
DaveA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

find all multiplicands and multipliers for a number ravas <ravas@outlook.com> - 2015-04-10 16:37 -0700
  Re: find all multiplicands and multipliers for a number Dave Angel <d@davea.name> - 2015-04-10 21:16 -0400
  Re: find all multiplicands and multipliers for a number Dave Angel <davea@davea.name> - 2015-04-10 21:06 -0400
    Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 12:04 +1000
      Re: find all multiplicands and multipliers for a number Stephen Tucker <stephen_tucker@sil.org> - 2015-04-11 06:11 +0100
      Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-10 23:08 -0700
        Re: find all multiplicands and multipliers for a number Marko Rauhamaa <marko@pacujo.net> - 2015-04-11 10:14 +0300
          Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-11 09:59 -0700
            Re: find all multiplicands and multipliers for a number Marko Rauhamaa <marko@pacujo.net> - 2015-04-11 20:31 +0300
              Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-11 10:52 -0700
                Re: find all multiplicands and multipliers for a number Chris Angelico <rosuav@gmail.com> - 2015-04-12 07:10 +1000
                Re: find all multiplicands and multipliers for a number Terry Reedy <tjreedy@udel.edu> - 2015-04-11 19:58 -0400
                Re: find all multiplicands and multipliers for a number Chris Angelico <rosuav@gmail.com> - 2015-04-12 10:16 +1000
          Re: find all multiplicands and multipliers for a number wolfram.hinderer@googlemail.com - 2015-04-11 16:17 -0700
            Re: find all multiplicands and multipliers for a number Marko Rauhamaa <marko@pacujo.net> - 2015-04-12 10:17 +0300
              Primes [was Re: find all multiplicands and multipliers for a number] Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 20:48 +1000
              Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 18:56 -0700
                Re: find all multiplicands and multipliers for a number Dave Angel <davea@davea.name> - 2015-04-12 22:35 -0400
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 20:30 -0700
                Re: find all multiplicands and multipliers for a number Dave Angel <davea@davea.name> - 2015-04-13 00:35 -0400
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 22:25 -0700
                Re: find all multiplicands and multipliers for a number Dave Angel <davea@davea.name> - 2015-04-13 01:43 -0400
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 22:57 -0700
                Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-13 17:21 +1000
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-13 19:42 -0700
                Re: find all multiplicands and multipliers for a number Chris Angelico <rosuav@gmail.com> - 2015-04-14 12:47 +1000
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-13 19:54 -0700
                Re: find all multiplicands and multipliers for a number Rustom Mody <rustompmody@gmail.com> - 2015-04-14 03:35 -0700
                Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-14 23:30 +1000
                Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-14 23:40 +1000
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-14 19:37 -0700
                Re: find all multiplicands and multipliers for a number Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-15 09:59 -0600
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-15 09:21 -0700
                Re: find all multiplicands and multipliers for a number Chris Kaynor <ckaynor@zindagigames.com> - 2015-04-15 09:46 -0700
                Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-15 10:37 -0700
                Searching the archives Gil Dawson <Gil@GilDawson.com> - 2015-04-15 11:47 -0700
                Installing Python Gil Dawson <Gil@GilDawson.com> - 2015-04-15 12:09 -0700
                Re: Searching the archives Tim Golden <mail@timgolden.me.uk> - 2015-04-15 20:16 +0100
                Re: Installing Python Ned Deily <nad@acm.org> - 2015-04-15 13:32 -0700
                Re: find all multiplicands and multipliers for a number Rustom Mody <rustompmody@gmail.com> - 2015-04-15 21:17 -0700
        Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 17:35 +1000
          Re: find all multiplicands and multipliers for a number jonas.thornvall@gmail.com - 2015-04-11 01:47 -0700
          Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-11 09:31 -0700
            Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 12:22 +1000
              Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-11 21:24 -0700
                Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-12 14:29 +1000
          Re: find all multiplicands and multipliers for a number Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-04-11 12:41 -0400
            Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-11 10:02 -0700
        Re: find all multiplicands and multipliers for a number Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-04-11 12:37 -0400
      Re: find all multiplicands and multipliers for a number Brian Gladman <blindanagram@nowhere.net> - 2015-04-12 10:34 +0100
        Re: find all multiplicands and multipliers for a number Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-13 00:29 +1000
          Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 10:20 -0700
            Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 10:23 -0700
            Re: find all multiplicands and multipliers for a number Brian Gladman <blindanagram@nowhere.net> - 2015-04-12 20:15 +0100
              Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-12 12:45 -0700
          Re: find all multiplicands and multipliers for a number Brian Gladman <blindanagram@nowhere.net> - 2015-04-12 20:07 +0100
  Re: find all multiplicands and multipliers for a number Paul Rubin <no.email@nospam.invalid> - 2015-04-10 18:28 -0700
  Re: find all multiplicands and multipliers for a number Dave Farrance <DaveFarrance@OMiTTHiSyahooANDTHiS.co.uk> - 2015-04-11 10:03 +0100
  Re: find all multiplicands and multipliers for a number ravas <ravas@outlook.com> - 2015-04-11 10:11 -0700

csiph-web