diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-02-06 07:08:39 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-06 07:08:39 +0000 |
| commit | 42eac9ec571c8a4d9f2b9e88ee926dbbd259cb49 (patch) | |
| tree | 7ff6ddb4e1e934f581eec8614188bdd6af877a47 | |
| parent | 6182aaf96d22af377994af61dec46e658b80a4fd (diff) | |
| parent | 69538a071b4d94aa3eef8e05e04f87aad4428fd8 (diff) | |
| download | perlweeklychallenge-club-42eac9ec571c8a4d9f2b9e88ee926dbbd259cb49.tar.gz perlweeklychallenge-club-42eac9ec571c8a4d9f2b9e88ee926dbbd259cb49.tar.bz2 perlweeklychallenge-club-42eac9ec571c8a4d9f2b9e88ee926dbbd259cb49.zip | |
Merge pull request #1216 from Cris-HD/branch-for-challenge-046
Added two solutions
| -rw-r--r-- | challenge-046/cristian-heredia/perl/ch-1.pl | 47 | ||||
| -rw-r--r-- | challenge-046/cristian-heredia/perl/ch-2.pl | 45 |
2 files changed, 92 insertions, 0 deletions
diff --git a/challenge-046/cristian-heredia/perl/ch-1.pl b/challenge-046/cristian-heredia/perl/ch-1.pl new file mode 100644 index 0000000000..38762ea171 --- /dev/null +++ b/challenge-046/cristian-heredia/perl/ch-1.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +#First, we write the message into arrays: +my @array1 = ('P', '+', '2', 'l', '!', 'a', 't', 'o' ); +my @array2 = ('1', 'e', '8', '0', 'R', '$', '4', 'u' ); +my @array3 = ('5', '-', 'r', ']', '+', 'a', '>', '/' ); +my @array4 = ('P', 'x', 'w', 'l', 'b', '3', 'k', '\\' ); +my @array5 = ('2', 'e', '3', '5', 'R', '8', 'y', 'u' ); +my @array6 = ('<', '!', 'r', '^', '(', ')', 'k', '0' ); + +my @arrayCharacter; + +print "The message is: "; +foreach (my $i = 0; $i < @array1; $i++) { + + @arrayCharacter = (); + push(@arrayCharacter, @array1[$i]); + push(@arrayCharacter, @array2[$i]); + push(@arrayCharacter, @array3[$i]); + push(@arrayCharacter, @array4[$i]); + push(@arrayCharacter, @array5[$i]); + push(@arrayCharacter, @array6[$i]); + + my %count; + $count{$_}++ foreach @arrayCharacter; + + #removing the lonely strings + while (my ($key, $value) = each(%count)) { + if ($value == 1) { + delete($count{$key}); + } + } + + #output the counts + while (my ($key, $value) = each(%count)) { + print "$key"; + } +} + + + + + + diff --git a/challenge-046/cristian-heredia/perl/ch-2.pl b/challenge-046/cristian-heredia/perl/ch-2.pl new file mode 100644 index 0000000000..3ddb12a79d --- /dev/null +++ b/challenge-046/cristian-heredia/perl/ch-2.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +my @rooms; +my $number; +my $size = 500; +#0 is closed +#1 is opened +foreach (my $i = 0; $i < $size; $i++) { + @rooms[$i] = 0; +} + +foreach (my $j = 0; $j < $size; $j++) { + + foreach (my $k = $j; $k < $size; $k = $j + $k +1) { + #If closed + if (@rooms[$k] == 0) { + @rooms[$k] = 1; + } + else { + @rooms[$k] = 0; + } + } +} + +print "The followings rooms are still open:\n"; + +foreach (my $x = 0; $x < $size; $x++) { + $number = $x +1; + if (@rooms[$x] == 1) { + print "The room $number\n"; + } +} + + + + + + + + + + |
