Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Comparing numbers

by jreades (Friar)
on Nov 29, 2002 at 11:28 UTC ( #216493=note: print w/ replies, xml ) Need Help??


in reply to Re: Comparing numbers
in thread Comparing numbers

You could also have some fun doing something like this:

my @numbers = ('0.13', '0.14', '0.14', '0.19', '0.21', '0.23', '0.45') +; my %differences = (); for (my $i = 0; $i < scalar(@numbers); $i++) { next if $i == 0; push @{$differences{($numbers[$i] - $numbers[$i - 1])}}, $numb +ers[$i] . " - " . $numbers[$i - 1]; } foreach (sort keys %differences) { print STDOUT "Difference ($_) occured: ", join (', ', @{$diffe +rences{$_}}), "\n" } exit 0;

I guess that's going beyond the exercise a little bit, but kind of fun and turned out this:

Difference (0) occured: 0.14 - 0.14 Difference (0.01) occured: 0.14 - 0.13 Difference (0.02) occured: 0.21 - 0.19, 0.23 - 0.21 Difference (0.05) occured: 0.19 - 0.14 Difference (0.22) occured: 0.45 - 0.23


Comment on Re: Re: Comparing numbers
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://216493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2015-07-30 02:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls