Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: Comparing numbers

by jreades (Friar)
on Nov 29, 2002 at 11:28 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found