go ahead... be a heretic | |
PerlMonks |
Re: Split range 0 to M into N non-overlapping (roughly equal) ranges.by roboticus (Chancellor) |
on Mar 12, 2011 at 16:58 UTC ( [id://892836]=note: print w/replies, xml ) | Need Help?? |
Hmmm ... I can make it differently, but no cleaner, unfortunately:
That one gets the second value wrong by one. I tried to find a way to stack the maps together, but couldn't figure out how to do it nicely. This one gets the values right, but uses an uglier map statement, and still requires the "$ranges[-1][1]=$M" line, which I don't particularly care for:
Perhaps one of these will be close enough to inspire a better solution for you? ...roboticus When your only tool is a hammer, all problems look like your thumb. Update: Added code tags to a bit of text so it renders correctly.
In Section
Seekers of Perl Wisdom
|
|