aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuiz Felipe <luizfelipecastrovb@gmail.com>2022-05-05 18:20:29 -0300
committerGitHub <noreply@github.com>2022-05-05 18:20:29 -0300
commit33e260c75e8464c38ed0a9cf81c87fd66a22a2c6 (patch)
treee85adb32d27c4d58ddc12cb037e3f31fe358b58b
parentd1befd1d56895d75eda1e212944b47b8e34a9002 (diff)
downloadperlweeklychallenge-club-33e260c75e8464c38ed0a9cf81c87fd66a22a2c6.tar.gz
perlweeklychallenge-club-33e260c75e8464c38ed0a9cf81c87fd66a22a2c6.tar.bz2
perlweeklychallenge-club-33e260c75e8464c38ed0a9cf81c87fd66a22a2c6.zip
Added the second challenge
-rw-r--r--challenge-163/luiz-felipe/perl/ch-2.pl31
1 files changed, 31 insertions, 0 deletions
diff --git a/challenge-163/luiz-felipe/perl/ch-2.pl b/challenge-163/luiz-felipe/perl/ch-2.pl
new file mode 100644
index 0000000000..be187bbc8e
--- /dev/null
+++ b/challenge-163/luiz-felipe/perl/ch-2.pl
@@ -0,0 +1,31 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use feature 'say';
+
+my (@numbers);
+
+@numbers = @ARGV or die "you need to pass the numbers to the script";
+
+say "The sum of these numbers is ", summations(@numbers);
+
+sub summations {
+ my (@numbers, $sum);
+
+ @numbers = @_;
+
+ while (scalar @numbers != 1) {
+ my (@summations, $sum);
+
+ $sum = 0;
+ foreach my $i (1..$#numbers) {
+ $sum += $numbers[$i];
+ push @summations, $sum;
+ }
+
+ @numbers = @summations;
+ }
+
+ return $numbers[0];
+}