aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCris-HD <59669732+Cris-HD@users.noreply.github.com>2020-03-08 18:29:59 +0100
committerCris-HD <59669732+Cris-HD@users.noreply.github.com>2020-03-08 18:29:59 +0100
commitb86d5eed8ea668f4e8cf3658a62bfafcf204a4d1 (patch)
tree84f8c78352914cf3284001ec3e7d03a9b6614e56
parentb13c136421244186da002ebdc7387bea05f1f19a (diff)
downloadperlweeklychallenge-club-b86d5eed8ea668f4e8cf3658a62bfafcf204a4d1.tar.gz
perlweeklychallenge-club-b86d5eed8ea668f4e8cf3658a62bfafcf204a4d1.tar.bz2
perlweeklychallenge-club-b86d5eed8ea668f4e8cf3658a62bfafcf204a4d1.zip
added ch-2.pl
-rw-r--r--challenge-050/cristian-heredia/perl/ch-2.pl69
1 files changed, 69 insertions, 0 deletions
diff --git a/challenge-050/cristian-heredia/perl/ch-2.pl b/challenge-050/cristian-heredia/perl/ch-2.pl
new file mode 100644
index 0000000000..bc66d4d721
--- /dev/null
+++ b/challenge-050/cristian-heredia/perl/ch-2.pl
@@ -0,0 +1,69 @@
+use strict;
+use warnings;
+
+#Noble Integer
+# You are given a list, @L,
+# of three or more random integers between 1 and 50. A Noble Integer is an integer N in @ L,
+# such that there are exactly N integers greater than N in @ L.
+# Output any Noble Integer found in @ L, or an empty list if none were found.
+#
+#An interesting question is whether or not there can be multiple Noble Integers in a list.
+#
+#For example,
+#
+#Suppose we have list of 4 integers[2, 6, 1, 3]
+#
+#Here we have 2 in the above list, known as Noble Integer, since there are exactly 2 integers in the list i.e. 3 and 6, which are greater than 2.
+#
+#Therefore the script would print 2.
+
+my $sizeArray = 4;
+my @array;
+my $start = 1;
+my $end = 50;
+my $random_number;
+my $total = 0;
+my $result = '';
+
+createArray();
+analizeArray();
+
+sub createArray {
+
+ for (my $i=0; $i<$sizeArray; $i++) {
+ $random_number = $start + int rand ($end - $start + 1);
+ $array[$i] = $random_number;
+ }
+
+ print "@array\n";
+}
+
+sub analizeArray {
+
+ for (my $j=0; $j<$sizeArray; $j++) {
+
+ for (my $k=0; $k<$sizeArray; $k++) {
+ if ($j == $k) {
+ }
+ elsif ($array[$j] < $array[$k]) {
+ $total++;
+ }
+ }
+
+ if ($total eq $array[$j] ) {
+ $result = $result."$array[$j] ";
+ }
+ $total = 0;
+ }
+
+ resultMessage();
+}
+
+sub resultMessage {
+ if ($result eq '') {
+ print "There isn't any result\n";
+ }
+ else {
+ print "The final result: $result\n";
+ }
+}