OK, I just couldn't give up on it. I've come up with two final solutions:

$ cat 892828_e.pl #!/usr/bin/perl use strict; use warnings; my ($MIN, $MAX, $N) = (12345, 9999997, 6); ### Inline version: my @R = ( map {$_*int($MAX/$N)} 0 .. $N-1 ); $R[$_] = [$R[$_],$R[$_+1]//$MAX] for 0 .. $N-1; print join("; ", map(join("-",@$_),@R)), "\n\n"; ### Subroutine version: @R = make_ranges($MIN, $MAX, $N); print join("; ", map(join("-",@$_),@R)), "\n\n"; sub make_ranges { my ($min, $max, $N) = @_; return [$min, $max] if $N ==1; my $newmax = $min + int( ($max-$min)/$N ); return [$min, $newmax], make_ranges($newmax+1, $max, $N-1); } Roboticus@Roboticus-PC ~ $ perl 892828_e.pl 0-1666666; 1666666-3333332; 3333332-4999998; 4999998-6666664; 6666664- +8333330; 8333330-9999997 12345-1676953; 1676954-3341562; 3341563-5006171; 5006172-6670780; 6670 +781-8335389; 8335390-9999997

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re^4: Split range 0 to M into N non-overlapping (roughly equal) ranges. by roboticus
in thread Split range 0 to M into N non-overlapping (roughly equal) ranges. by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.