diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2019-09-22 19:36:40 +0200 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2019-09-22 19:36:40 +0200 |
| commit | c50408a9b95805063e6a4016e38f4a2ae4ed2d86 (patch) | |
| tree | 46d4ddae1811d11f9eefe8fd5a2d89a99880cac3 /challenge-026 | |
| parent | b65067b778ddc88a8dd94ca2a2cad5a1838c58cb (diff) | |
| download | perlweeklychallenge-club-c50408a9b95805063e6a4016e38f4a2ae4ed2d86.tar.gz perlweeklychallenge-club-c50408a9b95805063e6a4016e38f4a2ae4ed2d86.tar.bz2 perlweeklychallenge-club-c50408a9b95805063e6a4016e38f4a2ae4ed2d86.zip | |
process array only once
Diffstat (limited to 'challenge-026')
| -rw-r--r-- | challenge-026/lubos-kolouch/perl5/ch-2.pl | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/challenge-026/lubos-kolouch/perl5/ch-2.pl b/challenge-026/lubos-kolouch/perl5/ch-2.pl index 96b5be4b04..2575514bae 100644 --- a/challenge-026/lubos-kolouch/perl5/ch-2.pl +++ b/challenge-026/lubos-kolouch/perl5/ch-2.pl @@ -30,8 +30,11 @@ sub get_mean { my ( $sin_sum, $cos_sum ); - $sin_sum += sin( deg2rad($_) ) for @angles; - $cos_sum += cos( deg2rad($_) ) for @angles; + for (@angles) { + $sin_sum += sin( deg2rad($_) ); + $cos_sum += cos( deg2rad($_) ); + } + return rad2deg( atan2( $sin_sum, $cos_sum ) ); } |
