in reply to Simple calculation.

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

Replies are listed 'Best First'.
Re^2: Simple calculation.
by BrowserUk (Patriarch) on May 09, 2015 at 09:01 UTC

    Hint: Retaining .05 precision in tick marks distributed over a range of 900+ doesn't make much sense.

    The kind of output I'm looking for for that example is:

    1,123,345,400 1,123,346,500 1,123,345,600 1,123,345,600 1,123,345,700 +1,123,345,800 1,123,345,900 1,123,346,000 1,123,346,100 1,123,346,200 + 1,123,346,300 1,123,346,400

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
      Hint: Retaining .05 precision in tick marks distributed over a range of 900+ doesn't make much sense.
      Makes perfect sense to me. I just thought that getting 8.721 as max is strange when the real max is 8.672. I actually thought your 'not so nice!' refers to that. I don't know how to produce "aethetically pleasing" numbers, sorry.
        Hmmm, BUK, you need approximately the number of ticks specified or the precise number? You said "Here, by inspection, we can conclude that the 'best' tick marks would probably be 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09. But that's only 8 ticks..." Is 8 ticks alright or do you need exactly 10? I was thinking about that and it's actually possible to produce 0.02, 0.03 .. 0.09 (and other "pretty" numbers like that), but I find your requirements not very clear, to be honest.