in reply to max of N numbers?

Although I don't agree with the question, an interesting solution does exist, I guess... Don't have time to explain it, but it's not that hard to figure out.
#!/usr/bin/perl use strict; use warnings; my @n = (2,3,4,7,8,9,10,8,20,9,7); my $m; foreach my $x (@n) { for (0..$#n) { my $y = $n[$_]; my $diff = abs($x - $y); $m = $x if $_ == $#n; next if $diff == 0; last if $diff + $x == $y; # Then y > x. } } print $m;

Replies are listed 'Best First'.
Re^2: max of N numbers?
by revdiablo (Prior) on May 28, 2006 at 19:14 UTC

    How exactly is == not a comparison operator? :-)

      Sorry, I got lazy and didn't complete the code. You can get rid of the ==s by simply subtracting the rhs from the left
      if $x == $y; if $x - $y;