diff options
| author | Solathian <horvath6@gmail.com> | 2022-11-20 12:59:02 +0100 |
|---|---|---|
| committer | Solathian <horvath6@gmail.com> | 2022-11-20 12:59:02 +0100 |
| commit | cf6ec1269c3b1c89f81d569e55fa53bfa94b1b29 (patch) | |
| tree | 4abeea4c550246b2e8c7c7462a522602792c3a52 | |
| parent | bde0adaf7b8dfe99c4e494c932d8702eb8cf9a56 (diff) | |
| download | perlweeklychallenge-club-cf6ec1269c3b1c89f81d569e55fa53bfa94b1b29.tar.gz perlweeklychallenge-club-cf6ec1269c3b1c89f81d569e55fa53bfa94b1b29.tar.bz2 perlweeklychallenge-club-cf6ec1269c3b1c89f81d569e55fa53bfa94b1b29.zip | |
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 |
