diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2022-11-21 01:06:17 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-11-21 01:06:17 +0000 |
| commit | 56d46a65e257fb28d597540f70d2adcf8326dc9d (patch) | |
| tree | b78b0e34dfdcb05e504b2b1e4ece214d51000228 | |
| parent | e8ec166ac7d9091a31aca74d0241a370d3767775 (diff) | |
| parent | cf6ec1269c3b1c89f81d569e55fa53bfa94b1b29 (diff) | |
| download | perlweeklychallenge-club-56d46a65e257fb28d597540f70d2adcf8326dc9d.tar.gz perlweeklychallenge-club-56d46a65e257fb28d597540f70d2adcf8326dc9d.tar.bz2 perlweeklychallenge-club-56d46a65e257fb28d597540f70d2adcf8326dc9d.zip | |
Merge pull request #7115 from Solathian/branch-for-challenge-191
Added file for challange 191
| -rw-r--r-- | challenge-191/solathian/perl/ch-1.pl | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/challenge-191/solathian/perl/ch-1.pl b/challenge-191/solathian/perl/ch-1.pl new file mode 100644 index 0000000000..6012f10f1c --- /dev/null +++ b/challenge-191/solathian/perl/ch-1.pl @@ -0,0 +1,51 @@ +#!usr/bin/perl -w +use v5.32; +use warnings; + +use feature 'signatures'; +no warnings 'experimental'; + +my $enableTests = 0; +# Challange 191 - 1 - Twice Largest +# You are given list of integers, @list. + +# Write a script to find out whether the largest item in the list is at least twice as large as +# each of the other items. + + +sub twiceLargest(@list) +{ + die "The given list has only one element. Stopped" if($#list == 0); + + @list = sort @list; + + print "\nThe largest in the given list is $list[-1]. "; + + if($list[-1] >= (2 * $list[-2]) ) + { + say "Also $list[-1] is greater than twice of every remaining elements." + } + else + { + say "However $list[-1] is not greater than twice of every remaining elements." + } + +} + + + +my @list0 = (1,2,3,4); +twiceLargest(@list0) if($enableTests); +# The largest in the given list is 4. However 4 is not greater than twice of every remaining elements. + +my @list1 = (1,2,0,5); +twiceLargest(@list1) if($enableTests); +# The largest in the given list is 5. Also 5 is greater than twice of every remaining elements. + +my @list2 = (2,6,3,1); +twiceLargest(@list2) if($enableTests); +# The largest in the given list is 6. Also 6 is greater than twice of every remaining elements. + +my @list3 = (4,5,2,3); +twiceLargest(@list3) if($enableTests); +# The largest in the given list is 5. Also 5 is not greater than twice of every remaining elements.
\ No newline at end of file |
