diff options
| -rw-r--r-- | challenge-110/paulo-custodio/Makefile | 2 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/python/ch-1.py | 39 | ||||
| -rw-r--r-- | challenge-110/paulo-custodio/python/ch-2.py | 47 | ||||
| -rwxr-xr-x | challenge-110/paulo-custodio/test.pl | 4 |
4 files changed, 88 insertions, 4 deletions
diff --git a/challenge-110/paulo-custodio/Makefile b/challenge-110/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-110/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-110/paulo-custodio/python/ch-1.py b/challenge-110/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..d0ae52b786 --- /dev/null +++ b/challenge-110/paulo-custodio/python/ch-1.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# 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 + +import fileinput +import sys +import re + +def is_valid_phone(phone): + return re.match(r"^\s*(?:\+\d{2}|\(\d{2}\)|\d{4})\s+\d{10}\s*$", phone) + +def filter_input(): + for phone in fileinput.input(): + phone = phone.strip() + if is_valid_phone(phone): + print(phone) + +filter_input() diff --git a/challenge-110/paulo-custodio/python/ch-2.py b/challenge-110/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..f73f24c8e9 --- /dev/null +++ b/challenge-110/paulo-custodio/python/ch-2.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +# 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 + +import fileinput +import sys + +def read_input(): + lines = [] + for line in fileinput.input(): + lines.append(line) + return lines + +def read_data(lines): + m = [] + for line in lines: + line = line.strip() + cols = line.split(',') + m.append(cols) + return m + +def transpose(m): + t = [[m[j][i] for j in range(len(m))] for i in range(len(m[0]))] + return t + +def print_data(m): + for row in m: + print(",".join(row)) + +print_data(transpose(read_data(read_input()))) diff --git a/challenge-110/paulo-custodio/test.pl b/challenge-110/paulo-custodio/test.pl deleted file mode 100755 index ba6c37260b..0000000000 --- a/challenge-110/paulo-custodio/test.pl +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env perl -use Modern::Perl; -use Test::More; -require '../../challenge-001/paulo-custodio/test.pl'; |
