Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Near equal partitions.

by nif (Sexton)
on Jan 14, 2011 at 16:55 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://882365]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-25 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found