aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-046/paulo-custodio/Makefile2
-rw-r--r--challenge-046/paulo-custodio/README1
-rw-r--r--challenge-046/paulo-custodio/perl/ch-1.pl57
-rw-r--r--challenge-046/paulo-custodio/perl/ch-2.pl26
-rw-r--r--challenge-046/paulo-custodio/t/test-1.yaml5
-rw-r--r--challenge-046/paulo-custodio/t/test-2.yaml5
6 files changed, 96 insertions, 0 deletions
diff --git a/challenge-046/paulo-custodio/Makefile b/challenge-046/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-046/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-046/paulo-custodio/README b/challenge-046/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-046/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-046/paulo-custodio/perl/ch-1.pl b/challenge-046/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..e5461d09b6
--- /dev/null
+++ b/challenge-046/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,57 @@
+#!/usr/bin/env perl
+
+# Challenge 046
+#
+# TASK #1
+# 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.
+
+use Modern::Perl;
+
+my @input =
+ ("P+2l!ato",
+ "1e80R\$4u",
+ "5-r]+a>/",
+ "Pxwlb3k\\",
+ "2e35R8yu",
+ "<!r^()k0");
+
+say decode(@input);
+
+sub decode {
+ my(@input) = @_;
+ my $decoded = "";
+ for my $col (0..length($input[0])-1) {
+ my %hist;
+ my $max_letter = ''; my $max_count = 0;
+ for my $row (@input) {
+ my $letter = substr($row, $col, 1);
+ $hist{$letter}++;
+ if ($hist{$letter} > $max_count) {
+ ($max_letter, $max_count) = ($letter, $hist{$letter});
+ }
+ }
+ $decoded .= $max_letter;
+ }
+ return $decoded;
+}
diff --git a/challenge-046/paulo-custodio/perl/ch-2.pl b/challenge-046/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..33cd97e265
--- /dev/null
+++ b/challenge-046/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,26 @@
+#!/usr/bin/env perl
+
+# Challenge 046
+#
+# TASK #2
+# 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 Modern::Perl;
+
+my @rooms = (0, (0)x500);
+for my $emp (1..500) {
+ for (my $door = $emp; $door < @rooms; $door += $emp) {
+ $rooms[$door] = 1-$rooms[$door];
+ }
+}
+my @doors = map {$_->[0]} grep {$_->[1]} map {[$_ => $rooms[$_]]} (1..500);
+say join(", ", @doors);
diff --git a/challenge-046/paulo-custodio/t/test-1.yaml b/challenge-046/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..d4da5ac307
--- /dev/null
+++ b/challenge-046/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: PerlRaku
diff --git a/challenge-046/paulo-custodio/t/test-2.yaml b/challenge-046/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..bfc39eaaed
--- /dev/null
+++ b/challenge-046/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400, 441, 484