diff options
59 files changed, 2767 insertions, 1912 deletions
diff --git a/.gitignore b/.gitignore index ba8194b15c..040286b6c4 100644 --- a/.gitignore +++ b/.gitignore @@ -19,5 +19,8 @@ go.mod go.sum tags +# Perl Inline module +_Inline + # Rust languageoutput directory target/ diff --git a/challenge-001/paulo-custodio/go.pl b/challenge-001/paulo-custodio/go.pl index fe74e50528..3904778b45 100644 --- a/challenge-001/paulo-custodio/go.pl +++ b/challenge-001/paulo-custodio/go.pl @@ -7,25 +7,11 @@ 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; -} +path("challenge-$nr/paulo-custodio")->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-001/paulo-custodio/untabify.pl b/challenge-001/paulo-custodio/untabify.pl index 9f3c5657d4..dfdd1f1143 100644 --- a/challenge-001/paulo-custodio/untabify.pl +++ b/challenge-001/paulo-custodio/untabify.pl @@ -10,6 +10,7 @@ for my $dir (<challenge-*/paulo-custodio>) { my $iter = path($dir)->iterator({recurse=>1}); while (defined(my $path = $iter->())) { next unless $path->is_file; + next unless -T $path; next if $path =~ /~$/; # temp files my $ext = ""; $path->basename =~ /(\.\w+)$/ and $ext = $1; next if $ext eq "" || $ext =~ /\.(exe|o|obj|ali|ads)$/; # binaries 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..cb66cbf59c --- /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..e2dd386ac1 --- /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..3e796f3de5 --- /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..764f673b5c --- /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() {} diff --git a/challenge-029/paulo-custodio/Makefile b/challenge-029/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-029/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-029/paulo-custodio/README b/challenge-029/paulo-custodio/README new file mode 100644 index 0000000000..87dc0b2fbd --- /dev/null +++ b/challenge-029/paulo-custodio/README @@ -0,0 +1 @@ +Solution by Paulo Custodio diff --git a/challenge-029/paulo-custodio/perl/ch-1.pl b/challenge-029/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..606ec245cf --- /dev/null +++ b/challenge-029/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,30 @@ +#!/usr/bin/perl + +# Challenge 029 + +# Task #1 +# Write a script to demonstrate brace expansion. For example, script would take +# command line argument Perl {Daily,Weekly,Monthly,Yearly} Challenge and should +# expand it and print like below: +# +# Perl Daily Challenge +# Perl Weekly Challenge +# Perl Monthly Challenge +# Perl Yearly Challenge + +use Modern::Perl; + +sub print_expanded { + my($text) = @_; + if ($text =~ /[{]([^{}]*?)[}]/) { + my($before, $expand, $after) = ($`, $1, $'); + for my $arg (split(/,/, $expand)) { + print_expanded($before.$arg.$after); + } + } + else { + say $text; + } +} + +print_expanded("@ARGV"); diff --git a/challenge-029/paulo-custodio/perl/ch-2.pl b/challenge-029/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..c33fa95943 --- /dev/null +++ b/challenge-029/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +# Challenge 029 + +# Task #2 +# Write a script to demonstrate calling a C function. It could be any user +# defined or standard C function. + +use Modern::Perl; +use Inline C => <<'END'; + int sum(int a, int b) { + return a+b; + } +END + +say sum(@ARGV); diff --git a/challenge-029/paulo-custodio/t/test-1.yaml b/challenge-029/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..9caa126714 --- /dev/null +++ b/challenge-029/paulo-custodio/t/test-1.yaml @@ -0,0 +1,22 @@ +- setup: + cleanup: + args: "'Perl {Daily,Weekly,Monthly,Yearly} Challenge'" + input: + output: | + Perl Daily Challenge + Perl Weekly Challenge + Perl Monthly Challenge + Perl Yearly Challenge +- setup: + cleanup: + args: "'a{b{1,2},c{3,4}}d'" + input: + output: | + ab1d + ac3d + ab1d + ac4d + ab2d + ac3d + ab2d + ac4d diff --git a/challenge-029/paulo-custodio/t/test-2.yaml b/challenge-029/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..45d285dccc --- /dev/null +++ b/challenge-029/paulo-custodio/t/test-2.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: 2 3 + input: + output: 5 diff --git a/challenge-142/paulo-custodio/perl/ch-1.pl b/challenge-142/paulo-custodio/perl/ch-1.pl index 76a8e19638..c29b6a64d8 100644 --- a/challenge-142/paulo-custodio/perl/ch-1.pl +++ b/challenge-142/paulo-custodio/perl/ch-1.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Challenge 142 +# # TASK #1 > Divisor Last Digit # Submitted by: Mohammad S Anwar # You are given positive integers, $m and $n. diff --git a/challenge-142/paulo-custodio/perl/ch-2.pl b/challenge-142/paulo-custodio/perl/ch-2.pl index 83160b0a28..a1da4960ff 100644 --- a/challenge-142/paulo-custodio/perl/ch-2.pl +++ b/challenge-142/paulo-custodio/perl/ch-2.pl @@ -1,5 +1,7 @@ #!/usr/bin/perl +# Challenge 142 +# # TASK #2 > Sleep Sort # Submitted by: Adam Russell # Another joke sort similar to JortSort suggested by champion Adam Russell. diff --git a/challenge-142/paulo-custodio/python/ch-1.py b/challenge-142/paulo-custodio/python/ch-1.py index d142b7d24f..99880d719a 100644 --- a/challenge-142/paulo-custodio/python/ch-1.py +++ b/challenge-142/paulo-custodio/python/ch-1.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +# Challenge 142 +# # TASK #1 > Divisor Last Digit # Submitted by: Mohammad S Anwar # You are given positive integers, $m and $n. diff --git a/challenge-142/paulo-custodio/python/ch-2.py b/challenge-142/paulo-custodio/python/ch-2.py index 31f6f67abe..cd84d4b50d 100644 --- a/challenge-142/paulo-custodio/python/ch-2.py +++ b/challenge-142/paulo-custodio/python/ch-2.py @@ -1,5 +1,7 @@ #!/usr/bin/python3 +# Challenge 142 +# # TASK #2 > Sleep Sort # Submitted by: Adam Russell # Another joke sort similar to JortSort suggested by champion Adam Russell. diff --git a/challenge-143/david-santiago/raku/ch-1.raku b/challenge-143/david-santiago/raku/ch-1.raku new file mode 100755 index 0000000000..65553e4fcd --- /dev/null +++ b/challenge-143/david-santiago/raku/ch-1.raku @@ -0,0 +1,5 @@ +use MONKEY-SEE-NO-EVAL; + +sub MAIN($expression) { + say EVAL $expression; +} diff --git a/challenge-143/david-santiago/raku/ch-2.raku b/challenge-143/david-santiago/raku/ch-2.raku new file mode 100755 index 0000000000..60007ddf5c --- /dev/null +++ b/challenge-143/david-santiago/raku/ch-2.raku @@ -0,0 +1,16 @@ +#!/usr/bin/env raku + +# bipronic numbers: +# Numbers of the form x*(x+1) * y*(y+1) ("bipronics") with x and y nonnegative integers. + +sub MAIN (Int $n){ + for (1..$n/2.ceiling) -> $a { + for (1..$a) -> $b { + if $a*($a+1) * $b*($b+1) == $n { + say "Yes"; + return; + } + } + } + say "No"; +} diff --git a/challenge-143/laurent-rosenfeld/blog.txt b/challenge-143/laurent-rosenfeld/blog.txt new file mode 100644 index 0000000000..3b1d505950 --- /dev/null +++ b/challenge-143/laurent-rosenfeld/blog.txt @@ -0,0 +1 @@ +http://blogs.perl.org/users/laurent_r/2021/12/post.html diff --git a/challenge-143/laurent-rosenfeld/perl/ch-1.pl b/challenge-143/laurent-rosenfeld/perl/ch-1.pl new file mode 100644 index 0000000000..bb8edda515 --- /dev/null +++ b/challenge-143/laurent-rosenfeld/perl/ch-1.pl @@ -0,0 +1,13 @@ +use strict; +use warnings; +use feature "say"; + +sub calc { + my $expr = shift; + return "Not a valid arithmetic expression" unless + $expr =~ /^[-\d\s+*()]+$/; + return eval $expr; +} +for my $test ("10 + 20 - 5", "(10 + 20 - 5) * 2", "7 + a", "6 * 7") { + say calc $test; +} diff --git a/challenge-143/laurent-rosenfeld/perl/ch-2.pl b/challenge-143/laurent-rosenfeld/perl/ch-2.pl new file mode 100644 index 0000000000..4c0d53cc74 --- /dev/null +++ b/challenge-143/laurent-rosenfeld/perl/ch-2.pl @@ -0,0 +1,33 @@ +use strict; +use warnings; +use feature "say"; + +sub cross { + my @nums = @_; + my @num_pairs; + for my $i (@nums) { + for my $j (@nums) { + next if $j > $i; # filter out duplicates such as [12, 3] and [3, 12] + push @num_pairs, [$i, $j]; + } + } + return @num_pairs; +} + +sub stealthy_nums { + my $n = shift; + my @divisors = grep {$n % $_ == 0} 1..$n; + my @div_pairs = grep { $_->[0] * $_->[1] == $n } cross @divisors; + for my $c (@div_pairs) { + for my $d (@div_pairs) { + return "@$c and @$d" if abs($c->[0] + $c->[1] - $d->[0] - $d->[1]) == 1; + } + } + return 0; +} + +for my $test (qw <36 12 6>) { + my $result = stealthy_nums $test; + say "$test \t", + $result ? "1 -> $result" : 0; +} diff --git a/challenge-143/laurent-rosenfeld/raku/ch-1.raku b/challenge-143/laurent-rosenfeld/raku/ch-1.raku new file mode 100644 index 0000000000..023b6d07d7 --- /dev/null +++ b/challenge-143/laurent-rosenfeld/raku/ch-1.raku @@ -0,0 +1,11 @@ +use v6; +use MONKEY-SEE-NO-EVAL; + +sub calc (Str $expr) { + return "Not a valid arithmetic expression" unless + $expr ~~ /^<[-\d \s +*()]>+$/; + return EVAL $expr; +} +for "10 + 20 - 5", "(10 + 20 - 5) * 2", "7 + a", "6 * 7" -> $test { + say calc $test; |
