aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCris-HD <crisn7@hotmail.com>2020-12-20 21:22:45 +0100
committerCris-HD <crisn7@hotmail.com>2020-12-20 21:22:45 +0100
commit985460bbfdc9aeeb90d5b700ecc2f83156ee3eba (patch)
treef6f371b5dd354f88ce888f6079020a0cf5134058
parentc19df7193f080b09fce8ba0d1179c796b7773ae2 (diff)
downloadperlweeklychallenge-club-985460bbfdc9aeeb90d5b700ecc2f83156ee3eba.tar.gz
perlweeklychallenge-club-985460bbfdc9aeeb90d5b700ecc2f83156ee3eba.tar.bz2
perlweeklychallenge-club-985460bbfdc9aeeb90d5b700ecc2f83156ee3eba.zip
Added challenge 91 solution
-rw-r--r--challenge-091/cristian-heredia/perl/ch-1.pl42
-rw-r--r--challenge-091/cristian-heredia/perl/ch-2.pl48
2 files changed, 90 insertions, 0 deletions
diff --git a/challenge-091/cristian-heredia/perl/ch-1.pl b/challenge-091/cristian-heredia/perl/ch-1.pl
new file mode 100644
index 0000000000..ef0c6c1c4d
--- /dev/null
+++ b/challenge-091/cristian-heredia/perl/ch-1.pl
@@ -0,0 +1,42 @@
+=begin
+
+TASK #1 › Count Number
+Submitted by: Mohammad S Anwar
+You are given a positive number $N.
+
+Write a script to count number and display as you read it.
+
+Example 1:
+Input: $N = 1122234
+Output: 21321314
+
+as we read "two 1 three 2 one 3 one 4"
+Example 2:
+Input: $N = 2333445
+Output: 12332415
+
+as we read "one 2 three 3 two 4 one 5"
+Example 3:
+Input: $N = 12345
+Output: 1112131415
+
+as we read "one 1 one 2 one 3 one 4 one 5"
+
+=end
+=cut
+
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my $N = '12345';
+my %data;
+
+my @array = split(//, $N);
+$data{$_}++ for @array;
+print "Output: ";
+foreach my $key ( sort { $a <=> $b } keys %data ) {
+ print "$data{$key}$key";
+}
+print "\n";
diff --git a/challenge-091/cristian-heredia/perl/ch-2.pl b/challenge-091/cristian-heredia/perl/ch-2.pl
new file mode 100644
index 0000000000..f9b1647063
--- /dev/null
+++ b/challenge-091/cristian-heredia/perl/ch-2.pl
@@ -0,0 +1,48 @@
+=begin
+
+ TASK #2 › Jump Game
+ Submitted by: Mohammad S Anwar
+ You are given an array of positive numbers @N, where value at each index determines how far you are allowed to jump further.
+
+ Write a script to decide if you can jump to the last index. Print 1 if you are able to reach the last index otherwise 0.
+
+ Example 1:
+ Input: @N = (1, 2, 1, 2)
+ Output: 1
+
+ as we jump one place from index 0 and then twoe places from index 1 to reach the last index.
+ Example 2:
+ Input: @N = (2,1,1,0,2)
+ Output: 0
+
+ it is impossible to reach the last index. as we jump two places from index 0 to reach index 2,
+ followed by one place jump from index 2 to reach the index 3. once you reached the index 3,
+ you can't go any further because you can only jump 0 position further.
+
+=end
+=cut
+
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+my @N = (1, 2, 1, 2);
+my $i = 0;
+my $position = 0;
+
+while ($i < @N && $i != @N - 1 and $N[$i] != 0){
+ $position = $N[$i];
+ $i = $position + $i;
+}
+if ($i == @N - 1) {
+ print "Output: 1\n";
+}
+else {
+ print "Output: 0\n";
+}
+
+
+
+
+