diff options
| -rw-r--r--[-rwxr-xr-x] | challenge-109/paulo-custodio/perl/ch-1.pl | 6 | ||||
| -rw-r--r--[-rwxr-xr-x] | challenge-109/paulo-custodio/perl/ch-2.pl | 12 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/people.txt | 5 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/perl/ch-1.pl | 29 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/perl/ch-2.pl | 42 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/phones.txt | 5 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/t/test-1.yaml | 8 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/t/test-2.yaml | 8 | ||||
| -rwxr-xr-x | challenge-110/paulo-custodio/test.pl | 7 |
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'; |
