diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-10 10:52:39 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-07-10 10:52:39 +0100 |
| commit | cc8580c1e95075ef7098044a075b037762ffd09a (patch) | |
| tree | 1921134d42932bbec406be79f41814229435bd3f /challenge-172 | |
| parent | 3d7f234add32dff5655c4e63fc506b2a8d016f19 (diff) | |
| download | perlweeklychallenge-club-cc8580c1e95075ef7098044a075b037762ffd09a.tar.gz perlweeklychallenge-club-cc8580c1e95075ef7098044a075b037762ffd09a.tar.bz2 perlweeklychallenge-club-cc8580c1e95075ef7098044a075b037762ffd09a.zip | |
- Added solution by Dario Mazzeo.
Diffstat (limited to 'challenge-172')
| -rwxr-xr-x | challenge-172/dario-mazzeo/perl/ch-2.pl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-172/dario-mazzeo/perl/ch-2.pl b/challenge-172/dario-mazzeo/perl/ch-2.pl new file mode 100755 index 0000000000..79749fa2cf --- /dev/null +++ b/challenge-172/dario-mazzeo/perl/ch-2.pl @@ -0,0 +1,25 @@ +# THE WEEKLY CHALLENGE - 172
+# Task 2: Five-number Summary
+# Autore: Dario Mazzeo
+
+my @numeri=(0, 0, 1, 2, 63, 61, 27, 13);
+#my @numeri=(77, 79, 80, 86, 87, 87, 94, 99);
+
+@numeri=sort {$a <=> $b} @numeri;
+my $min=$numeri[0];
+my $max=$numeri[$#numeri];
+
+my $mediana=0;
+if ($#numeri/2 != int($#numeri/2)){$mediana=($numeri[int($#numeri/2)] + $numeri[int($#numeri/2)+1])/2;}
+else{$mediana=$numeri[int($#numeri/2)]/2;}
+
+my $primoquartile=0;
+my $terzoquartile=0;
+for (my $i=1; $i<=($#numeri+1)/4; $i++){
+ $primoquartile+=$numeri[$i];
+ $terzoquartile+=$numeri[$#numeri-$i];
+}
+$primoquartile/=($#numeri+1)/4;
+$terzoquartile/=($#numeri+1)/4;
+
+printf("%.2f, %.2f, %.2f, %.2f, %.2f\n", $min, $primoquartile, $mediana, $terzoquartile, $max);
\ No newline at end of file |
