http://www.perlmonks.org?node_id=882365


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.