Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^2: Finding divisors from factors

by danaj (Friar)
on Oct 08, 2014 at 22:27 UTC ( #1103235=note: print w/replies, xml ) Need Help??

in reply to Re: Finding divisors from factors
in thread Finding divisors from factors

Thanks Rolf.

The powerset solution was mainly to point out this simple way. It does work -- one just needs to remove duplicates using a hash.

It looks like your solution is very similar to my followup, we just do the multiply through a little different. The time is pretty close, and both faster than my earlier solutions.

They also have the advantage of not doing excess computation, which is important when we move to bigints where every operation is expensive (with Math::BigInt at least).

Replies are listed 'Best First'.
Re^3: Finding divisors from factors (updated)
by LanX (Sage) on Oct 09, 2014 at 09:19 UTC
    Of course you can still speed up this solution, but I doubt it would be more than micro optimizations or just related to Perl specific features/bottlenecks (like overhead for allocating temporary arrays)

    This needs only one multiplication per divisor, hence its O(#D) i.e. <= O(2^#P) for worst case, that's pretty optimal.

    But I like the simplicity and readability compared to other suggestions, so personally I wouldn't start micro optimization now just to save 10 or 20 %.

    Of course I'm not comparing to solutions using XS modules. In that case just use C directly.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    ) or moving data or linearizing loops


    E.G. you could try to replace the maps with direct

    push @D_new, ($_*$p) for @D


    This could should be faster... but I'm not very motivated to benchmark myself. :)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1103235]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (None)
    As of 2022-01-26 06:13 GMT
    Find Nodes?
      Voting Booth?
      In 2022, my preferred method to securely store passwords is:

      Results (69 votes). Check out past polls.