diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-04-30 23:27:48 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-30 23:27:48 +0100 |
| commit | aa10d92be68bb71221ab18ecbc75bbd9b56b3c50 (patch) | |
| tree | 744fb1a4fbf5dfe3380128dc01f7920b6f61ef78 | |
| parent | 0162c1d30084a7c199196e30fb45e638e47dc4fb (diff) | |
| parent | 0588875440d9b4b38258db59b6d26426230dcf3c (diff) | |
| download | perlweeklychallenge-club-aa10d92be68bb71221ab18ecbc75bbd9b56b3c50.tar.gz perlweeklychallenge-club-aa10d92be68bb71221ab18ecbc75bbd9b56b3c50.tar.bz2 perlweeklychallenge-club-aa10d92be68bb71221ab18ecbc75bbd9b56b3c50.zip | |
Merge pull request #10013 from wlmb/challenges
Solve PWC267
| -rw-r--r-- | challenge-267/wlmb/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-267/wlmb/perl/ch-1.pl | 15 | ||||
| -rwxr-xr-x | challenge-267/wlmb/perl/ch-2.pl | 26 |
3 files changed, 42 insertions, 0 deletions
diff --git a/challenge-267/wlmb/blog.txt b/challenge-267/wlmb/blog.txt new file mode 100644 index 0000000000..7ac6e4e1a0 --- /dev/null +++ b/challenge-267/wlmb/blog.txt @@ -0,0 +1 @@ +https://wlmb.github.io/2024/04/29/PWC267/ diff --git a/challenge-267/wlmb/perl/ch-1.pl b/challenge-267/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..e730514e66 --- /dev/null +++ b/challenge-267/wlmb/perl/ch-1.pl @@ -0,0 +1,15 @@ +#!/usr/bin/env perl +# Perl weekly challenge 267 +# Task 1: Product Sign +# +# See https://wlmb.github.io/2024/04/29/PWC267/#task-1-product-sign +use v5.36; +use PDL; +die <<~"FIN" unless @ARGV; + Usage: $0 "x0 ẍ1..." ¨"y0 y1..." ... + to find the sign of the products x0 x1..., y0 y1..., etc. + FIN +for(@ARGV){ + my $x=pdl($_); + say "$x -> ", $x->prodover<=>0; +} diff --git a/challenge-267/wlmb/perl/ch-2.pl b/challenge-267/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..2ffd6748c0 --- /dev/null +++ b/challenge-267/wlmb/perl/ch-2.pl @@ -0,0 +1,26 @@ +#!/usr/bin/env perl +# Perl weekly challenge 267 +# Task 2: Line Counts +# +# See https://wlmb.github.io/2024/04/29/PWC267/#task-2-line-counts +use v5.36; +die <<~"FIN" unless @ARGV==27; + Usage: $0 S W1 W2...W26 + to find how many lines and additional characters are needed to print + the string S given the widths W1, W2..W26 of the letters a, b...z. + FIN + +my $line_width=100; +my $string=shift; +my @widths_ord=@ARGV; +my @widths_string=map {$widths_ord[ord($_)-ord("a")]} split "", $string; +my $current_line=1; # Note that I report one line, 0 chars for an empty string! +my $current_column = 0; # current column +for(@widths_string){ + $current_column += $_; + $current_column = $_, ++$current_line if $current_column > $line_width; + $current_column = 0, ++$current_line if $current_column == $line_width; + +} +say "string=$string\nwidths=\n\t@widths_ord[0..9]\n\t@widths_ord[10..19]", + "\n\t@widths_ord[20..25]\n -> ($current_line, $current_column)"; |
