aboutsummaryrefslogtreecommitdiff
path: root/challenge-042
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2022-04-06 16:59:19 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2022-04-06 16:59:19 +0100
commit5ab2802b060503486e6524b47689df72d8d7cd1c (patch)
treebe42a9936638766a351d6f6a771ce694ef020624 /challenge-042
parentf93043f673515bc8961338fb4c65ebd3fcc98b2e (diff)
downloadperlweeklychallenge-club-5ab2802b060503486e6524b47689df72d8d7cd1c.tar.gz
perlweeklychallenge-club-5ab2802b060503486e6524b47689df72d8d7cd1c.tar.bz2
perlweeklychallenge-club-5ab2802b060503486e6524b47689df72d8d7cd1c.zip
Add Perl solution to challenge 042
Diffstat (limited to 'challenge-042')
-rw-r--r--challenge-042/paulo-custodio/Makefile2
-rw-r--r--challenge-042/paulo-custodio/README1
-rw-r--r--challenge-042/paulo-custodio/perl/ch-1.pl27
-rw-r--r--challenge-042/paulo-custodio/perl/ch-2.pl24
-rw-r--r--challenge-042/paulo-custodio/t/test-1.yaml56
-rw-r--r--challenge-042/paulo-custodio/t/test-2.yaml13
6 files changed, 123 insertions, 0 deletions
diff --git a/challenge-042/paulo-custodio/Makefile b/challenge-042/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-042/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-042/paulo-custodio/README b/challenge-042/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-042/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-042/paulo-custodio/perl/ch-1.pl b/challenge-042/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..ca1246718e
--- /dev/null
+++ b/challenge-042/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,27 @@
+#!/usr/bin/env perl
+
+# Challenge 042
+#
+# TASK #1
+# Octal Number System
+# Write a script to print decimal number 0 to 50 in Octal Number System.
+#
+# For example:
+#
+# Decimal 0 = Octal 0
+# Decimal 1 = Octal 1
+# Decimal 2 = Octal 2
+# Decimal 3 = Octal 3
+# Decimal 4 = Octal 4
+# Decimal 5 = Octal 5
+# Decimal 6 = Octal 6
+# Decimal 7 = Octal 7
+# Decimal 8 = Octal 10
+# and so on.
+
+use Modern::Perl;
+use Math::BaseCnv;
+
+for (0..50) {
+ say "Decimal $_ = Octal ",cnv($_,10,8);
+}
diff --git a/challenge-042/paulo-custodio/perl/ch-2.pl b/challenge-042/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..f5a3afe5ed
--- /dev/null
+++ b/challenge-042/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/env perl
+
+# Challenge 042
+#
+# TASK #2
+# Balanced Brackets
+# Write a script to generate a string with random number of ( and ) brackets.
+# Then make the script validate the string if it has balanced brackets.
+#
+# For example:
+#
+# () - OK
+# (()) - OK
+# )( - NOT OK
+# ())() - NOT OK
+
+use Modern::Perl;
+
+while (<>) {
+ chomp;
+ print "$_ - ";
+ 1 while s/\(\)//;
+ say $_ eq '' ? "OK" : "NOT OK";
+}
diff --git a/challenge-042/paulo-custodio/t/test-1.yaml b/challenge-042/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..34693b8c6c
--- /dev/null
+++ b/challenge-042/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,56 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: |
+ |Decimal 0 = Octal 0
+ |Decimal 1 = Octal 1
+ |Decimal 2 = Octal 2
+ |Decimal 3 = Octal 3
+ |Decimal 4 = Octal 4
+ |Decimal 5 = Octal 5
+ |Decimal 6 = Octal 6
+ |Decimal 7 = Octal 7
+ |Decimal 8 = Octal 10
+ |Decimal 9 = Octal 11
+ |Decimal 10 = Octal 12
+ |Decimal 11 = Octal 13
+ |Decimal 12 = Octal 14
+ |Decimal 13 = Octal 15
+ |Decimal 14 = Octal 16
+ |Decimal 15 = Octal 17
+ |Decimal 16 = Octal 20
+ |Decimal 17 = Octal 21
+ |Decimal 18 = Octal 22
+ |Decimal 19 = Octal 23
+ |Decimal 20 = Octal 24
+ |Decimal 21 = Octal 25
+ |Decimal 22 = Octal 26
+ |Decimal 23 = Octal 27
+ |Decimal 24 = Octal 30
+ |Decimal 25 = Octal 31
+ |Decimal 26 = Octal 32
+ |Decimal 27 = Octal 33
+ |Decimal 28 = Octal 34
+ |Decimal 29 = Octal 35
+ |Decimal 30 = Octal 36
+ |Decimal 31 = Octal 37
+ |Decimal 32 = Octal 40
+ |Decimal 33 = Octal 41
+ |Decimal 34 = Octal 42
+ |Decimal 35 = Octal 43
+ |Decimal 36 = Octal 44
+ |Decimal 37 = Octal 45
+ |Decimal 38 = Octal 46
+ |Decimal 39 = Octal 47
+ |Decimal 40 = Octal 50
+ |Decimal 41 = Octal 51
+ |Decimal 42 = Octal 52
+ |Decimal 43 = Octal 53
+ |Decimal 44 = Octal 54
+ |Decimal 45 = Octal 55
+ |Decimal 46 = Octal 56
+ |Decimal 47 = Octal 57
+ |Decimal 48 = Octal 60
+ |Decimal 49 = Octal 61
+ |Decimal 50 = Octal 62
diff --git a/challenge-042/paulo-custodio/t/test-2.yaml b/challenge-042/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..6a6b817d08
--- /dev/null
+++ b/challenge-042/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,13 @@
+- setup:
+ cleanup:
+ args:
+ input: |
+ |()
+ |(())
+ |)(
+ |())()
+ output: |
+ |() - OK
+ |(()) - OK
+ |)( - NOT OK
+ |())() - NOT OK