in reply to Determine steps between two numbers
Since you always assemble your steps in increasing order, you could do this:
#!/usr/bin/perl use strict; use warnings; my ($first, $second, $steps) = @ARGV; $steps = int $steps; if ($first > $second) { ($first,$second) = ($second,$first); } my $increment = ($first - $second) / ($steps - 1); my @array = ($first); for (2..$steps) { push @array, $first -= $increment; } print join(", ", @array) . "\n";
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Determine steps between two numbers
by grizzley (Chaplain) on Sep 05, 2012 at 13:32 UTC | |
by thmsdrew (Scribe) on Sep 05, 2012 at 13:47 UTC | |
by CountZero (Bishop) on Sep 05, 2012 at 18:48 UTC | |
by thmsdrew (Scribe) on Sep 05, 2012 at 19:31 UTC | |
by CountZero (Bishop) on Sep 06, 2012 at 06:17 UTC | |
|
In Section
Cool Uses for Perl