in reply to Split range 0 to M into N non-overlapping (roughly equal) ranges.
Without additional variables, or special casing the last range:
All the ranges should differ at most 1 in size.my @ranges = map {[int($_*($M+1)/$N), int(($_+1)*(($M+1)/$N))-1]} 0..$ +N - 1;
|
---|
In Section
Seekers of Perl Wisdom