From c50408a9b95805063e6a4016e38f4a2ae4ed2d86 Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sun, 22 Sep 2019 19:36:40 +0200 Subject: process array only once --- challenge-026/lubos-kolouch/perl5/ch-2.pl | 7 +++++-- 1 file 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 ) ); } -- cgit