aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCris-HD <crisn7@hotmail.com>2020-11-08 15:36:38 +0100
committerCris-HD <crisn7@hotmail.com>2020-11-08 15:36:38 +0100
commit806617c4d64faf205d0097ab19dc007d3c30a4ff (patch)
treead1c338b50af61033661d10c324e187601778f5d
parent10f545e3c94e9f8d7948303fedeb79d367cc4e9d (diff)
downloadperlweeklychallenge-club-806617c4d64faf205d0097ab19dc007d3c30a4ff.tar.gz
perlweeklychallenge-club-806617c4d64faf205d0097ab19dc007d3c30a4ff.tar.bz2
perlweeklychallenge-club-806617c4d64faf205d0097ab19dc007d3c30a4ff.zip
Added challenge 85 solution
-rwxr-xr-xchallenge-085/cristian-heredia/perl/ch-1.pl39
-rwxr-xr-xchallenge-085/cristian-heredia/perl/ch-2.pl42
2 files changed, 81 insertions, 0 deletions
diff --git a/challenge-085/cristian-heredia/perl/ch-1.pl b/challenge-085/cristian-heredia/perl/ch-1.pl
new file mode 100755
index 0000000000..5fd7a2a283
--- /dev/null
+++ b/challenge-085/cristian-heredia/perl/ch-1.pl
@@ -0,0 +1,39 @@
+=begin
+ TASK #1 › Triplet Sum
+ Submitted by: Mohammad S Anwar
+ You are given an array of real numbers greater than zero.
+
+ Write a script to find if there exists a triplet (a,b,c) such that 1 < a+b+c < 2. Print 1 if you succeed otherwise 0.
+
+ Example 1:
+ Input: @R = (1.2, 0.4, 0.1, 2.5)
+ Output: 1 as 1 < 1.2 + 0.4 + 0.1 < 2
+ Example 2:
+ Input: @R = (0.2, 1.5, 0.9, 1.1)
+ Output: 0
+ Example 3:
+ Input: @R = (0.5, 1.1, 0.3, 0.7)
+ Output: 1 as 1 < 0.5 + 1.1 + 0.3 < 2
+=end
+=cut
+
+my @R = (0.5, 1.1, 0.3, 0.7);
+my $result = 0;
+
+foreach (my $i = 0; $i<@R; $i++) {
+ if ($R[$i] < 2 ) {
+ foreach (my $j = 0; $j<@R; $j++) {
+ if ($i != $j and ($R[$i] + $R[$i] < 2) ) {
+ foreach (my $k = 0; $k<@R; $k++) {
+ if ($i != $k and $j != $k and ($R[$i] + $R[$j] + $R[$k] < 2) and $result == 0 ) {
+ $result = 1;
+ print "Output: 1 as 1 < $R[$i]+ $R[$j] + $R[$k] < 2\n";
+ }
+ }
+ }
+ }
+ }
+}
+if ($result == 0) {
+ print "Output: 0\n";
+}
diff --git a/challenge-085/cristian-heredia/perl/ch-2.pl b/challenge-085/cristian-heredia/perl/ch-2.pl
new file mode 100755
index 0000000000..84521f9bec
--- /dev/null
+++ b/challenge-085/cristian-heredia/perl/ch-2.pl
@@ -0,0 +1,42 @@
+=begin
+ TASK #2 › Power of Two Integers
+ Submitted by: Mohammad S Anwar
+ You are given a positive integer $N.
+
+ Write a script to find if it can be expressed as a ** b where a > 0 and b > 1. Print 1 if you succeed otherwise 0.
+
+ Example 1:
+ Input: 8
+ Output: 1 as 8 = 2 ** 3
+ Example 2:
+ Input: 15
+ Output: 0
+ Example 3:
+ Input: 125
+ Output: 1 as 125 = 5 ** 3
+=end
+=cut
+
+my $N = 125;
+my $result;
+my $final = 0;
+
+calculateResult();
+
+sub calculateResult {
+
+ foreach(my $a = 1; $a < $N; $a++) {
+ foreach(my $b = 2; $b < $N; $b++) {
+ if ($final == 0) {
+ $result = $a ** $b;
+ if ($result == $N) {
+ $final = 1;
+ print "Output: 1 as $N = $a ** $b\n";
+ }
+ }
+ }
+ }
+ if ($final == 0) {
+ print "Output: 0\n";
+ }
+}