Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Near equal partitions.

by nif (Sexton)
on Jan 14, 2011 at 16:55 UTC ( #882365=note: print w/replies, xml ) Need Help??


in reply to Near equal partitions.

Sadly I was too late for the discussion...
The following modification with loop in place of divide operation is almost as fast as the winner, i never thought that divide is so slow.

sub part { my ($n, $m) = @_; my $q = 0; $q++ while ($n-=$m) > 0; return ($q+1) x ($n+$m), ($q) x (-$n); }
Update: $n in the Benchmark Re^3: Near equal partitions. is only in the range 2..100, for bigger numbers divide performs match better then the loop.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2020-01-28 07:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?