Thread an geringsten wert heranpirschen: in einem Array (3 answers)
Opened by mordur at 2005-01-28 17:48

Crian
 2005-01-28 18:13
#51415 #51415
User since
2003-08-04
5870 Artikel
ModeratorIn
[Homepage]
user image
Code: (dl )
1
2
3
my @array = (4, 1, 0, 9, 6, 7, 4, 0, 2);
my $v = 5;
print grep {abs($_-$v) == abs((sort {abs($a-$v) <=> abs($b-$v)} @array)[0]-$v)} @array;


absolut unoptimiert =)

Edit: Repariert (und getestet)\n\n

<!--EDIT|Crian|1106929576-->
s--Pevna-;s.([a-z]).chr((ord($1)-84)%26+97).gee; s^([A-Z])^chr((ord($1)-52)%26+65)^gee;print;

use strict; use warnings; Link zu meiner Perlseite

View full thread an geringsten wert heranpirschen: in einem Array