aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2021-06-14 21:06:04 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2021-06-14 21:06:04 +0100
commit7fe77aad9d67fa0f4f4d71845bb6b8c3416f6dbd (patch)
tree645fdc06130ef59857a13b26658416a449841c30
parent6ba8f88d505b0cf05dcc82c435372a4f45de891e (diff)
downloadperlweeklychallenge-club-7fe77aad9d67fa0f4f4d71845bb6b8c3416f6dbd.tar.gz
perlweeklychallenge-club-7fe77aad9d67fa0f4f4d71845bb6b8c3416f6dbd.tar.bz2
perlweeklychallenge-club-7fe77aad9d67fa0f4f4d71845bb6b8c3416f6dbd.zip
Add Perl solution to challenge 110
-rw-r--r--[-rwxr-xr-x]challenge-109/paulo-custodio/perl/ch-1.pl6
-rw-r--r--[-rwxr-xr-x]challenge-109/paulo-custodio/perl/ch-2.pl12
-rw-r--r--challenge-110/paulo-custodio/people.txt5
-rw-r--r--challenge-110/paulo-custodio/perl/ch-1.pl29
-rw-r--r--challenge-110/paulo-custodio/perl/ch-2.pl42
-rw-r--r--challenge-110/paulo-custodio/phones.txt5
-rw-r--r--challenge-110/paulo-custodio/t/test-1.yaml8
-rw-r--r--challenge-110/paulo-custodio/t/test-2.yaml8
-rwxr-xr-xchallenge-110/paulo-custodio/test.pl7
9 files changed, 113 insertions, 9 deletions
diff --git a/challenge-109/paulo-custodio/perl/ch-1.pl b/challenge-109/paulo-custodio/perl/ch-1.pl
index edb3e9769d..4015a4b8b2 100755..100644
--- a/challenge-109/paulo-custodio/perl/ch-1.pl
+++ b/challenge-109/paulo-custodio/perl/ch-1.pl
@@ -4,10 +4,10 @@
#
# TASK #1 - Chowla Numbers
# Submitted by: Mohammad S Anwar
-# Write a script to generate first 20 Chowla Numbers, named after,
-# Sarvadaman D. S. Chowla, a London born Indian American mathematician.
+# Write a script to generate first 20 Chowla Numbers, named after,
+# Sarvadaman D. S. Chowla, a London born Indian American mathematician.
# It is defined as:
-#
+#
# C(n) = sum of divisors of n except 1 and n
# NOTE: Updated the above definition as suggested by Abigail [2021/04/19 18:40].
# Output:
diff --git a/challenge-109/paulo-custodio/perl/ch-2.pl b/challenge-109/paulo-custodio/perl/ch-2.pl
index b168a71b1a..7c4e8226a3 100755..100644
--- a/challenge-109/paulo-custodio/perl/ch-2.pl
+++ b/challenge-109/paulo-custodio/perl/ch-2.pl
@@ -5,7 +5,7 @@
# TASK #2 - Four Squares Puzzle
# Submitted by: Mohammad S Anwar
# You are given four squares as below with numbers named a,b,c,d,e,f,g.
-#
+#
# (1) (3)
# ╔══════════════╗ ╔══════════════╗
# ║ ║ ║ ║
@@ -21,14 +21,14 @@
# │ │ │ │
# │ │ │ │
# └──────────────┘ └─────────────┘
-# Write a script to place the given unique numbers in the square box so that sum
+# Write a script to place the given unique numbers in the square box so that sum
# of numbers in each box is the same.
-#
+#
# Example
# Input: 1,2,3,4,5,6,7
-#
+#
# Output:
-#
+#
# a = 6
# b = 4
# c = 1
@@ -36,7 +36,7 @@
# e = 2
# f = 3
# g = 7
-#
+#
# Box 1: a + b = 6 + 4 = 10
# Box 2: b + c + d = 4 + 1 + 5 = 10
# Box 3: d + e + f = 5 + 2 + 3 = 10
diff --git a/challenge-110/paulo-custodio/people.txt b/challenge-110/paulo-custodio/people.txt
new file mode 100644
index 0000000000..716ebdce75
--- /dev/null
+++ b/challenge-110/paulo-custodio/people.txt
@@ -0,0 +1,5 @@
+name,age,sex
+Mohammad,45,m
+Joe,20,m
+Julie,35,f
+Cristina,10,f
diff --git a/challenge-110/paulo-custodio/perl/ch-1.pl b/challenge-110/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..493281da53
--- /dev/null
+++ b/challenge-110/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/env perl
+
+# Challenge 110
+#
+# TASK #1 - Valid Phone Numbers
+# Submitted by: Mohammad S Anwar
+# You are given a text file.
+#
+# Write a script to display all valid phone numbers in the given text file.
+#
+# Acceptable Phone Number Formats
+# +nn nnnnnnnnnn
+# (nn) nnnnnnnnnn
+# nnnn nnnnnnnnnn
+# Input File
+# 0044 1148820341
+# +44 1148820341
+# 44-11-4882-0341
+# (44) 1148820341
+# 00 1148820341
+# Output
+# 0044 1148820341
+# +44 1148820341
+# (44) 1148820341
+
+use Modern::Perl;
+while (<>) {
+ print if /^ \s* (?: \+ \d{2} | \( \d{2} \) | \d{4} ) \s+ \d{10} \s* $/x;
+}
diff --git a/challenge-110/paulo-custodio/perl/ch-2.pl b/challenge-110/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..2dbe0b8be8
--- /dev/null
+++ b/challenge-110/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,42 @@
+#!/usr/bin/env perl
+
+# Challenge 110
+#
+# TASK #2 - Transpose File
+# Submitted by: Mohammad S Anwar
+# You are given a text file.
+#
+# Write a script to transpose the contents of the given file.
+#
+# Input File
+# name,age,sex
+# Mohammad,45,m
+# Joe,20,m
+# Julie,35,f
+# Cristina,10,f
+# Output:
+# name,Mohammad,Joe,Julie,Cristina
+# age,45,20,35,10
+# sex,m,m,f,f
+
+use Modern::Perl;
+my @data;
+while (<>) {
+ chomp;
+ push @data, [split /,/, $_];
+}
+for (transpose(@data)) {
+ say join ',', @$_;
+}
+
+sub transpose {
+ my(@in) = @_;
+ my @out;
+ for my $row (0..$#in) {
+ for my $col (0 .. $#{$in[$row]}) {
+ $out[$col] ||= [];
+ $out[$col][$row] = $in[$row][$col];
+ }
+ }
+ return @out;
+}
diff --git a/challenge-110/paulo-custodio/phones.txt b/challenge-110/paulo-custodio/phones.txt
new file mode 100644
index 0000000000..48d6254741
--- /dev/null
+++ b/challenge-110/paulo-custodio/phones.txt
@@ -0,0 +1,5 @@
+0044 1148820341
+ +44 1148820341
+ 44-11-4882-0341
+(44) 1148820341
+ 00 1148820341
diff --git a/challenge-110/paulo-custodio/t/test-1.yaml b/challenge-110/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..84a2764e1f
--- /dev/null
+++ b/challenge-110/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,8 @@
+- setup:
+ cleanup:
+ args: phones.txt
+ input:
+ output: |
+ 0044 1148820341
+ +44 1148820341
+ (44) 1148820341
diff --git a/challenge-110/paulo-custodio/t/test-2.yaml b/challenge-110/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..bf58779c88
--- /dev/null
+++ b/challenge-110/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,8 @@
+- setup:
+ cleanup:
+ args: people.txt
+ input:
+ output: |
+ name,Mohammad,Joe,Julie,Cristina
+ age,45,20,35,10
+ sex,m,m,f,f
diff --git a/challenge-110/paulo-custodio/test.pl b/challenge-110/paulo-custodio/test.pl
new file mode 100755
index 0000000000..cf1ced98e0
--- /dev/null
+++ b/challenge-110/paulo-custodio/test.pl
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use 5.030;
+
+require '../../challenge-001/paulo-custodio/test.pl';