From 40ecb91eca8db21fb151ad8c148dd3e3b3f877c2 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 17 Dec 2021 11:48:55 +0000 Subject: Add Perl and Python solutions to challenge 028 --- challenge-001/paulo-custodio/go.pl | 38 +++++----- challenge-028/paulo-custodio/Makefile | 2 + challenge-028/paulo-custodio/README | 1 + challenge-028/paulo-custodio/perl/ch-1.pl | 19 +++++ challenge-028/paulo-custodio/perl/ch-2.pl | 106 ++++++++++++++++++++++++++++ challenge-028/paulo-custodio/python/ch-1.py | 17 +++++ challenge-028/paulo-custodio/python/ch-2.py | 89 +++++++++++++++++++++++ challenge-028/paulo-custodio/t/test-1.yaml | 10 +++ challenge-028/paulo-custodio/test.c | 1 + 9 files changed, 264 insertions(+), 19 deletions(-) create mode 100644 challenge-028/paulo-custodio/Makefile create mode 100644 challenge-028/paulo-custodio/README create mode 100644 challenge-028/paulo-custodio/perl/ch-1.pl create mode 100644 challenge-028/paulo-custodio/perl/ch-2.pl create mode 100644 challenge-028/paulo-custodio/python/ch-1.py create mode 100644 challenge-028/paulo-custodio/python/ch-2.py create mode 100644 challenge-028/paulo-custodio/t/test-1.yaml create mode 100644 challenge-028/paulo-custodio/test.c diff --git a/challenge-001/paulo-custodio/go.pl b/challenge-001/paulo-custodio/go.pl index fe74e50528..5278fa551b 100644 --- a/challenge-001/paulo-custodio/go.pl +++ b/challenge-001/paulo-custodio/go.pl @@ -7,25 +7,25 @@ use Path::Tiny; or die "Usage: ",path($0)->basename," nr\n"; my $nr = sprintf("%03d", $ARGV[0]); -for my $dir (qw( - ada - awk - basic - bc - brainfuck - c - cpp - d - forth - fortran - lua - pascal - perl - python - t - )) { - path("challenge-$nr/paulo-custodio/$dir")->mkpath; -} +#for my $dir (qw( +# ada +# awk +# basic +# bc +# brainfuck +# c +# cpp +# d +# forth +# fortran +# lua +# pascal +# perl +# python +# t +# )) { +# path("challenge-$nr/paulo-custodio/$dir")->mkpath; +#} path("challenge-$nr/paulo-custodio/README")->spew("Solution by Paulo Custodio\n"); if (! -f "challenge-$nr/paulo-custodio/Makefile") { path("challenge-$nr/paulo-custodio/Makefile")->spew( diff --git a/challenge-028/paulo-custodio/Makefile b/challenge-028/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-028/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-028/paulo-custodio/README b/challenge-028/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-028/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-028/paulo-custodio/perl/ch-1.pl b/challenge-028/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..40749c06b2 --- /dev/null +++ b/challenge-028/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,19 @@ +#!/usr/bin/perl + +# Challenge 028 + +# Task #1 +# Write a script to check the file content without explicitly reading the +# content. It should accept file name with path as command line argument and +# print "The file content is binary." or else "The file content is ascii." +# accordingly. + +use Modern::Perl; + +my $file = shift or die "Usage: $0 file\n"; +if (-T $file) { + say "The file content is ascii."; +} +else { + say "The file content is binary."; +} diff --git a/challenge-028/paulo-custodio/perl/ch-2.pl b/challenge-028/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..56e995663d --- /dev/null +++ b/challenge-028/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,106 @@ +#!/usr/bin/perl + +# Challenge 028 + +# Task #2 +# Write a script to display Digital Clock. Feel free to be as creative as you +# can when displaying digits. We expect bare minimum something like "14:10:11". + +use Modern::Perl; +use POSIX; +use Time::HiRes qw(usleep); + +my %chars; + +$chars{' '}[0] = " "; +$chars{' '}[1] = " "; +$chars{' '}[2] = " "; +$chars{' '}[3] = " "; +$chars{' '}[4] = " "; + +$chars{'0'}[0] = " ___ "; +$chars{'0'}[1] = " | |"; +$chars{'0'}[2] = " | |"; +$chars{'0'}[3] = " | |"; +$chars{'0'}[4] = " |___|"; + +$chars{'1'}[0] = " "; +$chars{'1'}[1] = " |"; +$chars{'1'}[2] = " |"; +$chars{'1'}[3] = " |"; +$chars{'1'}[4] = " |"; + +$chars{'2'}[0] = " ___ "; +$chars{'2'}[1] = " |"; +$chars{'2'}[2] = " ___|"; +$chars{'2'}[3] = " | "; +$chars{'2'}[4] = " |___ "; + +$chars{'3'}[0] = " ___ "; +$chars{'3'}[1] = " |"; +$chars{'3'}[2] = " ___|"; +$chars{'3'}[3] = " |"; +$chars{'3'}[4] = " ___|"; + +$chars{'4'}[0] = " "; +$chars{'4'}[1] = " | |"; +$chars{'4'}[2] = " |___|"; +$chars{'4'}[3] = " |"; +$chars{'4'}[4] = " |"; + +$chars{'5'}[0] = " ___ "; +$chars{'5'}[1] = " | "; +$chars{'5'}[2] = " |___ "; +$chars{'5'}[3] = " |"; +$chars{'5'}[4] = " ___|"; + +$chars{'6'}[0] = " ___ "; +$chars{'6'}[1] = " | "; +$chars{'6'}[2] = " |___ "; +$chars{'6'}[3] = " | |"; +$chars{'6'}[4] = " |___|"; + +$chars{'7'}[0] = " ___ "; +$chars{'7'}[1] = " | |"; +$chars{'7'}[2] = " | |"; +$chars{'7'}[3] = " |"; +$chars{'7'}[4] = " |"; + +$chars{'8'}[0] = " ___ "; +$chars{'8'}[1] = " | |"; +$chars{'8'}[2] = " |___|"; +$chars{'8'}[3] = " | |"; +$chars{'8'}[4] = " |___|"; + +$chars{'9'}[0] = " ___ "; +$chars{'9'}[1] = " | |"; +$chars{'9'}[2] = " |___|"; +$chars{'9'}[3] = " |"; +$chars{'9'}[4] = " ___|"; + +$chars{':'}[0] = " "; +$chars{':'}[1] = " "; +$chars{':'}[2] = " . "; +$chars{':'}[3] = " . "; +$chars{':'}[4] = " "; + +my $CLEAR = "\e[H\e[2J"; +my $HOME = "\e[H"; + +sub banner { + my($text) = @_; + for my $row (0 .. $#{$chars{' '}}) { + for my $c (split(//, $text)) { + print $chars{$c}[$row]; + } + print "\n"; + } +} + +print $CLEAR; +while (1) { + my $time = strftime("%H:%M:%S", localtime(time)); + print $HOME; + banner($time); + usleep(500*1000); +} diff --git a/challenge-028/paulo-custodio/python/ch-1.py b/challenge-028/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..2ed8ff5b7b --- /dev/null +++ b/challenge-028/paulo-custodio/python/ch-1.py @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +# Challenge 028 + +# Task #1 +# Write a script to check the file content without explicitly reading the +# content. It should accept file name with path as command line argument and +# print "The file content is binary." or else "The file content is ascii." +# accordingly. + +import sys + +file = sys.argv[1] +if b'\x00' in open(file, 'rb').read(): + print("The file content is binary.") +else: + print("The file content is ascii.") diff --git a/challenge-028/paulo-custodio/python/ch-2.py b/challenge-028/paulo-custodio/python/ch-2.py new file mode 100644 index 0000000000..51771c3ad9 --- /dev/null +++ b/challenge-028/paulo-custodio/python/ch-2.py @@ -0,0 +1,89 @@ +#!/usr/bin/python3 + +# Challenge 028 + +# Task #2 +# Write a script to display Digital Clock. Feel free to be as creative as you +# can when displaying digits. We expect bare minimum something like "14:10:11". + +from datetime import datetime +import time + +chars = { + ' ': [" ", + " ", + " ", + " ", + " "], + '0': [" ___ ", + " | |", + " | |", + " | |", + " |___|"], + '1': [" ", + " |", + " |", + " |", + " |"], + '2': [" ___ ", + " |", + " ___|", + " | ", + " |___ "], + '3': [" ___ ", + " |", + " ___|", + " |", + " ___|"], + '4': [" ", + " | |", + " |___|", + " |", + " |"], + '5': [" ___ ", + " | ", + " |___ ", + " |", + " ___|"], + '6': [" ___ ", + " | ", + " |___ ", + " | |", + " |___|"], + '7': [" ___ ", + " | |", + " | |", + " |", + " |"], + '8': [" ___ ", + " | |", + " |___|", + " | |", + " |___|"], + '9': [" ___ ", + " | |", + " |___|", + " |", + " ___|"], + ':': [" ", + " ", + " . ", + " . ", + " "], +} + +CLEAR = "\x1b[H\x1b[2J" +HOME = "\x1b[H" + +def banner(text): + for row in range(len(chars[' '])): + for c in text: + print(chars[c][row], end="") + print("") + +print(CLEAR, end="") +while True: + now = datetime.now() + print(HOME, end="") + banner(now.strftime("%H:%M:%S")) + time.sleep(0.5) diff --git a/challenge-028/paulo-custodio/t/test-1.yaml b/challenge-028/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..866183cedc --- /dev/null +++ b/challenge-028/paulo-custodio/t/test-1.yaml @@ -0,0 +1,10 @@ +- setup: system("gcc -otest test.c")==0 + cleanup: + args: test.c + input: + output: The file content is ascii. +- setup: + cleanup: unlink("test.o", "test") + args: test + input: + output: The file content is binary. diff --git a/challenge-028/paulo-custodio/test.c b/challenge-028/paulo-custodio/test.c new file mode 100644 index 0000000000..237c8ce181 --- /dev/null +++ b/challenge-028/paulo-custodio/test.c @@ -0,0 +1 @@ +int main() {} -- cgit From 994fa45410ba8f2eeb4992d35a44e41bf973869c Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 17 Dec 2021 11:54:21 +0000 Subject: Whitespace --- challenge-028/paulo-custodio/perl/ch-1.pl | 4 ++-- challenge-028/paulo-custodio/perl/ch-2.pl | 22 +++++++++++----------- challenge-028/paulo-custodio/python/ch-2.py | 2 +- challenge-028/paulo-custodio/t/test-1.yaml | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/challenge-028/paulo-custodio/perl/ch-1.pl b/challenge-028/paulo-custodio/perl/ch-1.pl index 40749c06b2..cb66cbf59c 100644 --- a/challenge-028/paulo-custodio/perl/ch-1.pl +++ b/challenge-028/paulo-custodio/perl/ch-1.pl @@ -12,8 +12,8 @@ use Modern::Perl; my $file = shift or die "Usage: $0 file\n"; if (-T $file) { - say "The file content is ascii."; + say "The file content is ascii."; } else { - say "The file content is binary."; + say "The file content is binary."; } diff --git a/challenge-028/paulo-custodio/perl/ch-2.pl b/challenge-028/paulo-custodio/perl/ch-2.pl index 56e995663d..6664df0349 100644 --- a/challenge-028/paulo-custodio/perl/ch-2.pl +++ b/challenge-028/paulo-custodio/perl/ch-2.pl @@ -88,19 +88,19 @@ my $CLEAR = "\e[H\e[2J"; my $HOME = "\e[H"; sub banner { - my($text) = @_; - for my $row (0 .. $#{$chars{' '}}) { - for my $c (split(//, $text)) { - print $chars{$c}[$row]; - } - print "\n"; - } + my($text) = @_; + for my $row (0 .. $#{$chars{' '}}) { + for my $c (split(//, $text)) { + print $chars{$c}[$row]; + } + print "\n"; + } } print $CLEAR; while (1) { - my $time = strftime("%H:%M:%S", localtime(time)); - print $HOME; - banner($time); - usleep(500*1000); + my $time = strftime("%H:%M:%S", localtime(time)); + print $HOME; + banner($time); + usleep(500*1000); } diff --git a/challenge-028/paulo-custodio/python/ch-2.py b/challenge-028/paulo-custodio/python/ch-2.py index 51771c3ad9..a96d8442f9 100644 --- a/challenge-028/paulo-custodio/python/ch-2.py +++ b/challenge-028/paulo-custodio/python/ch-2.py @@ -9,7 +9,7 @@ from datetime import datetime import time -chars = { +chars = { ' ': [" ", " ", " ", diff --git a/challenge-028/paulo-custodio/t/test-1.yaml b/challenge-028/paulo-custodio/t/test-1.yaml index 866183cedc..764f673b5c 100644 --- a/challenge-028/paulo-custodio/t/test-1.yaml +++ b/challenge-028/paulo-custodio/t/test-1.yaml @@ -1,9 +1,9 @@ - setup: system("gcc -otest test.c")==0 - cleanup: + cleanup: args: test.c input: output: The file content is ascii. -- setup: +- setup: cleanup: unlink("test.o", "test") args: test input: -- cgit From ef3944bc3d9772d7a4b950682a046e0fb185f8d8 Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Fri, 17 Dec 2021 12:02:21 +0000 Subject: Change image of 7 and 9 --- challenge-028/paulo-custodio/perl/ch-2.pl | 6 +++--- challenge-028/paulo-custodio/python/ch-2.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/challenge-028/paulo-custodio/perl/ch-2.pl b/challenge-028/paulo-custodio/perl/ch-2.pl index 6664df0349..e2dd386ac1 100644 --- a/challenge-028/paulo-custodio/perl/ch-2.pl +++ b/challenge-028/paulo-custodio/perl/ch-2.pl @@ -61,8 +61,8 @@ $chars{'6'}[3] = " | |"; $chars{'6'}[4] = " |___|"; $chars{'7'}[0] = " ___ "; -$chars{'7'}[1] = " | |"; -$chars{'7'}[2] = " | |"; +$chars{'7'}[1] = " |"; +$chars{'7'}[2] = " |"; $chars{'7'}[3] = " |"; $chars{'7'}[4] = " |"; @@ -76,7 +76,7 @@ $chars{'9'}[0] = " ___ "; $chars{'9'}[1] = " | |"; $chars{'9'}[2] = " |___|"; $chars{'9'}[3] = " |"; -$chars{'9'}[4] = " ___|"; +$chars{'9'}[4] = " |"; $chars{':'}[0] = " "; $chars{':'}[1] = " "; diff --git a/challenge-028/paulo-custodio/python/ch-2.py b/challenge-028/paulo-custodio/python/ch-2.py index a96d8442f9..3e796f3de5 100644 --- a/challenge-028/paulo-custodio/python/ch-2.py +++ b/challenge-028/paulo-custodio/python/ch-2.py @@ -51,8 +51,8 @@ chars = { " | |", " |___|"], '7': [" ___ ", - " | |", - " | |", + " |", + " |", " |", " |"], '8': [" ___ ", @@ -64,7 +64,7 @@ chars = { " | |", " |___|", " |", - " ___|"], + " |"], ':': [" ", " ", " . ", -- cgit