aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraliciabielsa <aliciabielsa@gmail.com>2020-02-07 18:55:31 +0100
committeraliciabielsa <aliciabielsa@gmail.com>2020-02-07 18:55:31 +0100
commit7d3e17da4de0db3c9e51b2b2f14499ef56821fe8 (patch)
tree80eeaf8516b839a4194fda191182e4704e6bffe9
parent4888342870a94bcc70bdb3b8e87f4ac1946098d2 (diff)
downloadperlweeklychallenge-club-7d3e17da4de0db3c9e51b2b2f14499ef56821fe8.tar.gz
perlweeklychallenge-club-7d3e17da4de0db3c9e51b2b2f14499ef56821fe8.tar.bz2
perlweeklychallenge-club-7d3e17da4de0db3c9e51b2b2f14499ef56821fe8.zip
challenge 046
-rw-r--r--challenge-046/alicia-bielsa/perl/ch-1.pl55
-rw-r--r--challenge-046/alicia-bielsa/perl/ch-2.pl32
2 files changed, 87 insertions, 0 deletions
diff --git a/challenge-046/alicia-bielsa/perl/ch-1.pl b/challenge-046/alicia-bielsa/perl/ch-1.pl
new file mode 100644
index 0000000000..e2ff41d1b4
--- /dev/null
+++ b/challenge-046/alicia-bielsa/perl/ch-1.pl
@@ -0,0 +1,55 @@
+
+use strict;
+use warnings;
+use Data::Dumper;
+
+#Cryptic Message
+#The communication system of an office is broken and message received are not completely reliable. To send message Hello, it ended up sending these following:
+#
+#H x l 4 !
+#c e - l o
+#z e 6 l g
+#H W l v R
+#q 9 m # o
+#Similary another day we received a message repeatedly like below:
+#
+#P + 2 l ! a t o
+#1 e 8 0 R $ 4 u
+#5 - r ] + a > /
+#P x w l b 3 k \
+#2 e 3 5 R 8 y u
+#< ! r ^ ( ) k 0
+#Write a script to decrypt the above repeated message (one message repeated 6 times).
+#
+#HINT: Look for characters repeated in a particular position in all six messages received.
+
+my @aMessage1 = qw(P + 2 l ! a t o);
+my @aMessage2 = qw(1 e 8 0 R $ 4 u);
+my @aMessage3 = qw(5 - r ] + a > /);
+my @aMessage4 = qw(P x w l b 3 k \\);
+my @aMessage5 = qw(2 e 3 5 R 8 y u);
+my @aMessage6 = qw(< ! r ^ ( ) k 0);
+my @aCharactersRepeated = ();
+my $lengthMessage = scalar(@aMessage1);
+my @aAllMessages = (@aMessage1, @aMessage2 ,@aMessage3, @aMessage4, @aMessage5 ,@aMessage6);
+my %hCharacters = ();
+
+foreach my $indexAllMesages (0..$#aAllMessages){
+ my $indexMessage = $indexAllMesages % $lengthMessage;
+ my $currentCharacter = $aAllMessages[$indexAllMesages];
+ unless (exists($hCharacters{$indexMessage})){
+ $hCharacters{$indexMessage} =();
+ }
+ unless (exists($hCharacters{$indexMessage}{$currentCharacter})){
+ $hCharacters{$indexMessage}{$currentCharacter} = 0 ;
+ }
+ $hCharacters{$indexMessage}{$currentCharacter} ++;
+ if ($hCharacters{$indexMessage}{$currentCharacter} == 2 ){
+ $aCharactersRepeated[$indexMessage] = $currentCharacter;
+ }
+}
+print "Decrypted Message:";
+foreach my $character (@aCharactersRepeated){
+ print "$character";
+}
+print "\n";
diff --git a/challenge-046/alicia-bielsa/perl/ch-2.pl b/challenge-046/alicia-bielsa/perl/ch-2.pl
new file mode 100644
index 0000000000..26e3cefb6b
--- /dev/null
+++ b/challenge-046/alicia-bielsa/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#Is the room open?
+#There are 500 rooms in a hotel with 500 employees having keys to all the rooms.
+#The first employee opened main entrance door of all the rooms. The second employee then closed the doors of room numbers 2,4,6,8,10 and so on to 500. The third employee then closed the door if it was opened or opened the door if it was closed of rooms 3,6,9,12,15 and so on to 500. Similarly the fourth employee did the same as the third but only room numbers 4,8,12,16 and so on to 500. This goes on until all employees has had a turn.
+#
+#Write a script to find out all the rooms still open at the end.
+
+use strict;
+use warnings;
+
+my $TOTAL = 500;
+my @aRooms = (0) x $TOTAL;
+foreach my $employee (1..$TOTAL){
+ foreach my $door ($employee..$TOTAL){
+ if ($door % $employee == 0 ){
+ $aRooms[$door-1] = flipStatus ($aRooms[$door-1]);
+ }
+ }
+}
+
+foreach my $room (0..$#aRooms){
+ if ($aRooms[$room]){
+ $room ++;
+ print "Room $room opened\n";
+ }
+}
+sub flipStatus {
+ my $status = shift;
+ if ($status){
+ return 0;
+ }
+ return 1;
+} \ No newline at end of file