Mmmm, I think the formula is (end - start) / (number_of_parts - 1).
use strict; use warnings; use feature 'say'; display_parts( 0, 9, 10 ); display_parts( 0.022, 0.086, 10 ); display_parts( 0.123, 8.672, 10 ); display_parts( 1_123_345_456, 1_124_246_357.5, 11 ); sub display_parts { my $result = get_ticks(@_); printf "start: %s, end: %s, parts: %s\n", map pretty($_), @_; for ( 0 .. $#$result ) { printf " %2d => %s\n", $_, pretty( $result->[$_] ); } print "\n"; } sub get_ticks { my ( $start, $end, $parts ) = @_; my $tick = ( $end - $start ) / ( $parts - 1 ); my @result; push @result, $start; push @result, $result[-1] + $tick for 1 .. ($parts - 1); return \@result; } sub pretty { return shift =~ s/\d \K (?= (?: \d{3} )+ \b )/_/xgr; }
output:
start: 0, end: 9, parts: 10 0 => 0 1 => 1 2 => 2 3 => 3 4 => 4 5 => 5 6 => 6 7 => 7 8 => 8 9 => 9 start: 0.022, end: 0.086, parts: 10 0 => 0.022 1 => 0.0_291_111_111_111_111 2 => 0.0_362_222_222_222_222 3 => 0.0_433_333_333_333_333 4 => 0.0_504_444_444_444_444 5 => 0.0_575_555_555_555_555 6 => 0.0_646_666_666_666_667 7 => 0.0_717_777_777_777_778 8 => 0.0_788_888_888_888_889 9 => 0.086 start: 0.123, end: 8.672, parts: 10 0 => 0.123 1 => 1.07_288_888_888_889 2 => 2.02_277_777_777_778 3 => 2.97_266_666_666_667 4 => 3.92_255_555_555_556 5 => 4.87_244_444_444_445 6 => 5.82_233_333_333_333 7 => 6.77_222_222_222_222 8 => 7.72_211_111_111_111 9 => 8.672 start: 1_123_345_456, end: 1_124_246_357.5, parts: 11 0 => 1_123_345_456 1 => 1_123_435_546.15 2 => 1_123_525_636.3 3 => 1_123_615_726.45 4 => 1_123_705_816.6 5 => 1_123_795_906.75 6 => 1_123_885_996.9 7 => 1_123_976_087.05 8 => 1_124_066_177.2 9 => 1_124_156_267.35 10 => 1_124_246_357.5

In reply to Re: Simple calculation. by Anonymous Monk
in thread Simple calculation. 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.