From f817d0e37bc5dd80c7aabcca52f4c28d16316e66 Mon Sep 17 00:00:00 2001 From: "Jaldhar H. Vyas" Date: Mon, 6 Mar 2023 02:53:02 -0500 Subject: Challenge 206 by Jaldhar H. Vyas. --- challenge-206/jaldhar-h-vyas/blog.txt | 1 + challenge-206/jaldhar-h-vyas/perl/ch-1.pl | 31 +++++++++++ challenge-206/jaldhar-h-vyas/perl/ch-2.pl | 81 +++++++++++++++++++++++++++++ challenge-206/jaldhar-h-vyas/raku/ch-1.raku | 16 ++++++ challenge-206/jaldhar-h-vyas/raku/ch-2.raku | 18 +++++++ 5 files changed, 147 insertions(+) create mode 100644 challenge-206/jaldhar-h-vyas/blog.txt create mode 100755 challenge-206/jaldhar-h-vyas/perl/ch-1.pl create mode 100755 challenge-206/jaldhar-h-vyas/perl/ch-2.pl create mode 100755 challenge-206/jaldhar-h-vyas/raku/ch-1.raku create mode 100755 challenge-206/jaldhar-h-vyas/raku/ch-2.raku diff --git a/challenge-206/jaldhar-h-vyas/blog.txt b/challenge-206/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..e032944f1c --- /dev/null +++ b/challenge-206/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2023/03/perl_weekly_challenge_week_206.html \ No newline at end of file diff --git a/challenge-206/jaldhar-h-vyas/perl/ch-1.pl b/challenge-206/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..1cbf6a1ba4 --- /dev/null +++ b/challenge-206/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub combinations { + my @list = @{$_[0]}; + my $length = $_[1]; + + if ($length <= 1) { + return map [$_], @list; + } + + my @combos; + + for (my $i = 0; $i + $length <= scalar @list; $i++) { + my $val = $list[$i]; + my @rest = @list[$i + 1 .. $#list]; + for my $c (combinations(\@rest, $length - 1)) { + push @combos, [$val, @{$c}] ; + } + } + + return @combos; +} + +my @times = map { + my ($h, $m) = split /\:/, $_; + ($h == 0 && $m == 0 ? 1440 : $h * 60) + $m; + } @ARGV; + +say 0+(sort { $a <=> $b } map { abs (@$_[0] - @$_[1]) } combinations(\@times, 2))[0]; diff --git a/challenge-206/jaldhar-h-vyas/perl/ch-2.pl b/challenge-206/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..67045bbdf0 --- /dev/null +++ b/challenge-206/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,81 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub batch { + my @range = @{$_[0]}; + my $quantity = $_[1]; + + if ($quantity < 1 || $quantity > scalar @range) { + die "out of range\n"; + } + + my $length = scalar @range; + my $i = 0; + while ($i < $length) { + my @row; + for (1 .. $quantity) { + push @row, shift @range; + $i++; + if ($i == $length) { + last; + } + } + push @range, [@row]; + } + + return wantarray ? @range : $range[0]; +} + +sub permute (&@) { + my $code = shift; + my @idx = 0..$#_; + while ( $code->(@_[@idx]) ) { + my $p = $#idx; + --$p while $idx[$p-1] > $idx[$p]; + my $q = $p or return; + push @idx, reverse splice @idx, $p; + ++$q while $idx[$p-1] > $idx[$q]; + @idx[$p-1,$q]=@idx[$q,$p-1]; + } +} + +sub unique { + my %seen; + for my $elem (@_) { + $seen{$elem}++; + } + return keys %seen; +} + +sub min { + return $_[0] < $_[1] ? $_[0] : $_[1]; +} + +sub sum { + my ($arr) = @_; + my $total = 0; + + for my $elem (@{$arr}) { + $total += $elem; + } + + return $total; +} + +my @permutations; +permute { push @permutations, \@_; } @ARGV; + +say [ + sort { $b <=> $a } + map { sum([map { min(@{$_}) } @{$_}]) } + map { [batch($_, 2)] } + map { [ split // ] } + unique( + map { join q{}, @{$_} } + map { [map { sort { $a <=> $b } @{$_} } @{$_}] } + map { [batch($_, 2)] } + grep { $_->[0] == $ARGV[0] } + @permutations + ) +]->[0]; diff --git a/challenge-206/jaldhar-h-vyas/raku/ch-1.raku b/challenge-206/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..33f5495e26 --- /dev/null +++ b/challenge-206/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,16 @@ +#!/usr/bin/raku + +sub MAIN( + *@args +) { + @args + .map({ + my ($h, $m) = $_.split(/\:/); + ($h == 0 && $m == 0 ?? 1440 !! $h * 60) + $m; + }) + .combinations(2) + .map({ (@$_[0] - @$_[1]).abs }) + .sort({ $^a <=> $^b }) + .first + .say; +} \ No newline at end of file diff --git a/challenge-206/jaldhar-h-vyas/raku/ch-2.raku b/challenge-206/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..89e96ada09 --- /dev/null +++ b/challenge-206/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,18 @@ +#!/usr/bin/raku + +sub MAIN( + *@args +) { + @args + .permutations + .grep({ @$_[0] == @args[0]; }) + .map({ $_.batch(2); }) + .map({ $_.map({ $_.sort({ $^a <=> $^b }); }) }) + .map({ join(q{}, | @$_); }) + .unique + .map({ $_.comb; }) + .map({ $_.batch(2); }) + .map({ [+] $_.map({ $_.min; }) }) + .max + .say; +} \ No newline at end of file -- cgit From 0160b6d96c3d18016cff236d65a796a2cb2061d6 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 6 Mar 2023 10:08:53 +0000 Subject: Challenge 207 Solutions (Raku) --- challenge-207/mark-anderson/raku/ch-1.raku | 11 +++++++++++ challenge-207/mark-anderson/raku/ch-2.raku | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 challenge-207/mark-anderson/raku/ch-1.raku create mode 100644 challenge-207/mark-anderson/raku/ch-2.raku diff --git a/challenge-207/mark-anderson/raku/ch-1.raku b/challenge-207/mark-anderson/raku/ch-1.raku new file mode 100644 index 0000000000..3f25b822a7 --- /dev/null +++ b/challenge-207/mark-anderson/raku/ch-1.raku @@ -0,0 +1,11 @@ +#!/usr/bin/env raku +use Test; + +is keyboard-word(< Hello Alaska Dad Peace >), < Alaska Dad >; +is keyboard-word(< OMG Bye >), < >; +is keyboard-word(< BBC CNN OAN >), < BBC CNN >; + +sub keyboard-word(@a) +{ + @a.grep({ .lc.comb.cache (<=) any < qwertyuiop asdfghjkl zxcvbnm >>>.comb }) +} diff --git a/challenge-207/mark-anderson/raku/ch-2.raku b/challenge-207/mark-anderson/raku/ch-2.raku new file mode 100644 index 0000000000..c7daf9dfd7 --- /dev/null +++ b/challenge-207/mark-anderson/raku/ch-2.raku @@ -0,0 +1,17 @@ +#!/usr/bin/env raku +use Test; + +is h-index(10, 8, 5, 4, 3), 4; +is h-index(25, 8, 5, 3, 3), 3; +is h-index(25, 8, 3, 3, 3), 3; +is h-index(3), 1; +is h-index(3, 2), 2; +is h-index(0, 0, 0, 0, 0), 0; +is h-index(0, 0, 0, 0, 1), 1; +is h-index(1, 1, 1, 1, 1), 1; +is h-index(9, 9, 9, 9, 9), 5; + +sub h-index(*@a) +{ + .sort(-*).pairs.first({ .key >= .value }).key // .elems given @a +} -- cgit From ebebdc959141caca7cec4b4d6c374c6e90a575ca Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 6 Mar 2023 10:14:00 +0000 Subject: Challenge 207 Solutions (Raku) --- challenge-207/mark-anderson/raku/ch-1.raku | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/challenge-207/mark-anderson/raku/ch-1.raku b/challenge-207/mark-anderson/raku/ch-1.raku index 3f25b822a7..de15caf680 100644 --- a/challenge-207/mark-anderson/raku/ch-1.raku +++ b/challenge-207/mark-anderson/raku/ch-1.raku @@ -1,9 +1,9 @@ #!/usr/bin/env raku use Test; -is keyboard-word(< Hello Alaska Dad Peace >), < Alaska Dad >; -is keyboard-word(< OMG Bye >), < >; -is keyboard-word(< BBC CNN OAN >), < BBC CNN >; +is-deeply keyboard-word(< Hello Alaska Dad Peace >), < Alaska Dad >; +is-deeply keyboard-word(< OMG Bye >), < >; +is-deeply keyboard-word(< BBC CNN OAN >), < BBC CNN >; sub keyboard-word(@a) { -- cgit From 299ccd70e466a89c89980e77d01abcd19e0cedd8 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 6 Mar 2023 10:29:02 +0000 Subject: Challenge 207 Solutions (Raku) --- challenge-207/mark-anderson/raku/ch-1.raku | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/challenge-207/mark-anderson/raku/ch-1.raku b/challenge-207/mark-anderson/raku/ch-1.raku index de15caf680..d226573ccc 100644 --- a/challenge-207/mark-anderson/raku/ch-1.raku +++ b/challenge-207/mark-anderson/raku/ch-1.raku @@ -1,11 +1,11 @@ #!/usr/bin/env raku use Test; -is-deeply keyboard-word(< Hello Alaska Dad Peace >), < Alaska Dad >; -is-deeply keyboard-word(< OMG Bye >), < >; -is-deeply keyboard-word(< BBC CNN OAN >), < BBC CNN >; +is-deeply keyboard-word(< Hello Alaska Dad Peace >), < Alaska Dad >; +is-deeply keyboard-word(< OMG Bye >), < >; +is-deeply keyboard-word(< BBC CNN OAN >), < BBC CNN >; sub keyboard-word(@a) { - @a.grep({ .lc.comb.cache (<=) any < qwertyuiop asdfghjkl zxcvbnm >>>.comb }) + @a.grep({ .lc.comb.cache (<) any < qwertyuiop asdfghjkl zxcvbnm >>>.comb }) } -- cgit From 2bce548e7e0cb6afa22b65a272bb1a455f3b4022 Mon Sep 17 00:00:00 2001 From: Mark <53903062+andemark@users.noreply.github.com> Date: Mon, 6 Mar 2023 10:33:24 +0000 Subject: Challenge 207 Solutions (Raku) --- challenge-207/mark-anderson/raku/ch-1.raku | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/challenge-207/mark-anderson/raku/ch-1.raku b/challenge-207/mark-anderson/raku/ch-1.raku index d226573ccc..667171e7db 100644 --- a/challenge-207/mark-anderson/raku/ch-1.raku +++ b/challenge-207/mark-anderson/raku/ch-1.raku @@ -7,5 +7,5 @@ is-deeply keyboard-word(< BBC CNN OAN >), < BBC CNN >; sub keyboard-word(@a) { - @a.grep({ .lc.comb.cache (<) any < qwertyuiop asdfghjkl zxcvbnm >>>.comb }) + @a.grep({ .lc.comb.cache (<=) any < qwertyuiop asdfghjkl zxcvbnm >>>.comb }) } -- cgit From 3517fe82e657ed522b51bd1e527fa266509bb2a2 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 13:46:53 +0100 Subject: Task 1 done --- challenge-207/luca-ferrari/raku/ch-1.p6 | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 challenge-207/luca-ferrari/raku/ch-1.p6 diff --git a/challenge-207/luca-ferrari/raku/ch-1.p6 b/challenge-207/luca-ferrari/raku/ch-1.p6 new file mode 100644 index 0000000000..129b1111bc --- /dev/null +++ b/challenge-207/luca-ferrari/raku/ch-1.p6 @@ -0,0 +1,24 @@ +#!raku + +# +# Perl Weekly Challenge 207 +# Task 1 +# +# See +# + +sub MAIN( *@words ) { + my @keyboard = qw/ qwertyuiop asdfghjkl zxcvbnm /; + + for @words -> $current-word { + for @keyboard -> $current-row { + my $found = 0; + for $current-word.lc.comb -> $current-letter { + $found++ if ( $current-row ~~ /$current-letter/ ); + } + + $current-word.say if $current-word.chars == $found; + } + } + +} -- cgit From 0f5dafd2a98bacb9993430b3d128800623a3b1fd Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 14:21:37 +0100 Subject: Task 2 done --- challenge-207/luca-ferrari/raku/ch-2.p6 | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 challenge-207/luca-ferrari/raku/ch-2.p6 diff --git a/challenge-207/luca-ferrari/raku/ch-2.p6 b/challenge-207/luca-ferrari/raku/ch-2.p6 new file mode 100644 index 0000000000..9fe10ca663 --- /dev/null +++ b/challenge-207/luca-ferrari/raku/ch-2.p6 @@ -0,0 +1,20 @@ +#!raku + +# +# Perl Weekly Challenge 207 +# Task 2 +# +# See +# + + +# The H-Index is the largest number h such that h articles have at least h citations each. +# For example, if an author has five publications, with 9, 7, 6, 2, and 1 citations +# (ordered from greatest to least), +# then the author’s h-index is 3, because the author has three publications +# with 3 or more citations. +# However, the author does not have four publications with 4 or more citations. + +sub MAIN( *@citations where { @citations.grep( * ~~ Int ).elems == @citations.elems } ) { + @citations.sort.reverse.pairs.first( { $_.key >= $_.value } ).key.say; +} -- cgit From c9b06033cc830ad98c41f599d770c4707ec51b39 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 14:27:32 +0100 Subject: Task 1 plperl done --- challenge-207/luca-ferrari/postgresql/ch-1.plperl | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 challenge-207/luca-ferrari/postgresql/ch-1.plperl diff --git a/challenge-207/luca-ferrari/postgresql/ch-1.plperl b/challenge-207/luca-ferrari/postgresql/ch-1.plperl new file mode 100644 index 0000000000..f40c97ae1e --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-1.plperl @@ -0,0 +1,34 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 1 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task1_plperl( text[] ) +RETURNS SETOF text +AS $CODE$ + + my ( $words ) = @_; + my ( @keyboard ) = qw/ qwertyuiop asdfghjkl zxcvbnm /; + + for my $current_word ( $words->@* ) { + for my $current_row ( @keyboard ) { + my $found = 0; + for my $current_letter ( split( '', lc( $current_word ) ) ) { + $found++ if ( $current_row =~ /$current_letter/ ); + } + + if ( scalar( split( '', $current_word ) ) == $found ) { + return_next( $current_word ); + last; + } + } + } + + return undef; + +$CODE$ +LANGUAGE plperl; -- cgit From e85bd4e453aeb9ea1bb5400f756c4c9ee05c73fb Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 14:42:30 +0100 Subject: Task 2 plperl done --- challenge-207/luca-ferrari/postgresql/ch-2.plperl | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 challenge-207/luca-ferrari/postgresql/ch-2.plperl diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.plperl b/challenge-207/luca-ferrari/postgresql/ch-2.plperl new file mode 100644 index 0000000000..1f31604070 --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-2.plperl @@ -0,0 +1,23 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 2 +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task2_plperl( int[] ) +RETURNS int +AS $CODE$ + + my ( $citations ) = @_; + my @cits = reverse sort $citations->@*; + my @data; + while ( my ( $key, $value ) = each( @cits ) ) { + push @data, $value if ( $key >= $value ); + } + + return ( sort( @data ) )[ 0 ]; +$CODE$ +LANGUAGE plperl; -- cgit From 9da9431a3fb1038c78b894003d1d754de5296afd Mon Sep 17 00:00:00 2001 From: boblied Date: Mon, 6 Mar 2023 07:54:54 -0600 Subject: update README for 207 --- challenge-207/bob-lied/README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/challenge-207/bob-lied/README b/challenge-207/bob-lied/README index 4dcb1ff367..bb94b2f9bc 100644 --- a/challenge-207/bob-lied/README +++ b/challenge-207/bob-lied/README @@ -1,4 +1,4 @@ -Solutions to weekly challenge 206 by Bob Lied +Solutions to weekly challenge 207 by Bob Lied -https://perlweeklychallenge.org/blog/perl-weekly-challenge-206/ -https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-206/bob-lied +https://perlweeklychallenge.org/blog/perl-weekly-challenge-207/ +https://github.com/boblied/perlweeklychallenge-club/tree/master/challenge-207/bob-lied -- cgit From 54d3ee59eaf7a05196696b9582d43d046d2b1193 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 14:58:23 +0100 Subject: Task 1 sql done --- challenge-207/luca-ferrari/postgresql/ch-1.sql | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 challenge-207/luca-ferrari/postgresql/ch-1.sql diff --git a/challenge-207/luca-ferrari/postgresql/ch-1.sql b/challenge-207/luca-ferrari/postgresql/ch-1.sql new file mode 100644 index 0000000000..477bf9703f --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-1.sql @@ -0,0 +1,45 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 1 +-- +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task1_plpgsql( w text[] ) +RETURNS SETOF text +AS $CODE$ +DECLARE + current_word text; + current_row text; + letters_found int; +BEGIN + + CREATE TEMPORARY TABLE IF NOT EXISTS keyboard( k text ); + TRUNCATE keyboard; + INSERT INTO keyboard( k ) + VALUES( 'qwertyuiop' ), ( 'asdfghjkl' ), ( 'zxcvbnm' ); + + FOREACH current_word IN ARRAY w LOOP + FOR current_row IN SELECT k FROM keyboard LOOP + letters_found := 0; + + SELECT count(*) + INTO letters_found + FROM regexp_split_to_table( current_word, '' ) ww + JOIN regexp_split_to_table( current_row, '' ) kk + ON ww = kk; + + IF letters_found = length( current_word ) THEN + RETURN NEXT current_word; + EXIT; + END IF; + END LOOP; + END LOOP; + +RETURN; +END +$CODE$ +LANGUAGE plpgsql; -- cgit From 694750e37b300fb1d3978bf4dac7a206dd7f4d7d Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 15:03:30 +0100 Subject: Task 2 sql done --- challenge-207/luca-ferrari/postgresql/ch-2.sql | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 challenge-207/luca-ferrari/postgresql/ch-2.sql diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.sql b/challenge-207/luca-ferrari/postgresql/ch-2.sql new file mode 100644 index 0000000000..5e2e7d5820 --- /dev/null +++ b/challenge-207/luca-ferrari/postgresql/ch-2.sql @@ -0,0 +1,26 @@ +-- +-- Perl Weekly Challenge 207 +-- Task 2 +-- +-- See +-- + +CREATE SCHEMA IF NOT EXISTS pwc207; + +CREATE OR REPLACE FUNCTION +pwc207.task2_plpgsql( citations int[] ) +RETURNS SETOF int +AS $CODE$ +DECLARE +BEGIN + RETURN QUERY WITH d AS ( + SELECT c, row_number() OVER ( ORDER BY c desc ) r + FROM unnest( citations ) c + ) + SELECT MIN( c ) + FROM d + WHERE c >= r + ; +END +$CODE$ +LANGUAGE plpgsql; -- cgit From 05bd21e48e0310a256750ea2b421f758f68d2b40 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 15:15:42 +0100 Subject: Fix key/value --- challenge-207/luca-ferrari/postgresql/ch-2.plperl | 2 +- challenge-207/luca-ferrari/postgresql/ch-2.sql | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.plperl b/challenge-207/luca-ferrari/postgresql/ch-2.plperl index 1f31604070..6794b73618 100644 --- a/challenge-207/luca-ferrari/postgresql/ch-2.plperl +++ b/challenge-207/luca-ferrari/postgresql/ch-2.plperl @@ -15,7 +15,7 @@ AS $CODE$ my @cits = reverse sort $citations->@*; my @data; while ( my ( $key, $value ) = each( @cits ) ) { - push @data, $value if ( $key >= $value ); + push @data, $key if ( $key >= $value ); } return ( sort( @data ) )[ 0 ]; diff --git a/challenge-207/luca-ferrari/postgresql/ch-2.sql b/challenge-207/luca-ferrari/postgresql/ch-2.sql index 5e2e7d5820..a0daf6681a 100644 --- a/challenge-207/luca-ferrari/postgresql/ch-2.sql +++ b/challenge-207/luca-ferrari/postgresql/ch-2.sql @@ -17,9 +17,9 @@ BEGIN SELECT c, row_number() OVER ( ORDER BY c desc ) r FROM unnest( citations ) c ) - SELECT MIN( c ) + SELECT MIN( r ) FROM d - WHERE c >= r + WHERE r >= c ; END $CODE$ -- cgit From 879d890fe3656f7394a5f15e7b61747a73444f18 Mon Sep 17 00:00:00 2001 From: Luca Ferrari Date: Mon, 6 Mar 2023 15:23:01 +0100 Subject: Blog references --- challenge-207/luca-ferrari/blog-1.txt | 1 + challenge-207/luca-ferrari/blog-2.txt | 1 + challenge-207/luca-ferrari/blog-3.txt | 1 + challenge-207/luca-ferrari/blog-4.txt | 1 + challenge-207/luca-ferrari/blog-5.txt | 1 + challenge-207/luca-ferrari/blog-6.txt | 1 + 6 files changed, 6 insertions(+) create mode 100644 challenge-207/luca-ferrari/blog-1.txt create mode 100644 challenge-207/luca-ferrari/blog-2.txt create mode 100644 challenge-207/luca-ferrari/blog-3.txt create mode 100644 challenge-207/luca-ferrari/blog-4.txt create mode 100644 challenge-207/luca-ferrari/blog-5.txt create mode 100644 challenge-207/luca-ferrari/blog-6.txt diff --git a/challenge-207/luca-ferrari/blog-1.txt b/challenge-207/luca-ferrari/blog-1.txt new file mode 100644 index 0000000000..198c9de319 --- /dev/null +++ b/challenge-207/luca-ferrari/blog-1.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task1 diff --git a/challenge-207/luca-ferrari/blog-2.txt b/challenge-207/luca-ferrari/blog-2.txt new file mode 100644 index 0000000000..2bdda598ec --- /dev/null +++ b/challenge-207/luca-ferrari/blog-2.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task2 diff --git a/challenge-207/luca-ferrari/blog-3.txt b/challenge-207/luca-ferrari/blog-3.txt new file mode 100644 index 0000000000..8c2bdc218e --- /dev/null +++ b/challenge-207/luca-ferrari/blog-3.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task1plperl diff --git a/challenge-207/luca-ferrari/blog-4.txt b/challenge-207/luca-ferrari/blog-4.txt new file mode 100644 index 0000000000..e310a1b0b6 --- /dev/null +++ b/challenge-207/luca-ferrari/blog-4.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task2plperl diff --git a/challenge-207/luca-ferrari/blog-5.txt b/challenge-207/luca-ferrari/blog-5.txt new file mode 100644 index 0000000000..589e0e9013 --- /dev/null +++ b/challenge-207/luca-ferrari/blog-5.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task1plpgsql diff --git a/challenge-207/luca-ferrari/blog-6.txt b/challenge-207/luca-ferrari/blog-6.txt new file mode 100644 index 0000000000..f66ba42c5e --- /dev/null +++ b/challenge-207/luca-ferrari/blog-6.txt @@ -0,0 +1 @@ +https://fluca1978.github.io/2023/03/06/PerlWeeklyChallenge207.html#task2plpgsql -- cgit From a7426dfa56f1ed4e603dbbc3e48aca51140edb35 Mon Sep 17 00:00:00 2001 From: boblied Date: Mon, 6 Mar 2023 08:39:49 -0600 Subject: Week 207 Task 1 --- challenge-207/bob-lied/perl/ch-1.pl | 60 +++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 challenge-207/bob-lied/perl/ch-1.pl diff --git a/challenge-207/bob-lied/perl/ch-1.pl b/challenge-207/bob-lied/perl/ch-1.pl new file mode 100644 index 0000000000..6341985f6c --- /dev/null +++ b/challenge-207/bob-lied/perl/ch-1.pl @@ -0,0 +1,60 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-1.pl Perl Weekly Challenge Week 207 Task 1 Keyboard Words +#============================================================================= +# Copyright (c) 2023, Bob Lied +#============================================================================= +# You are given an array of words. +# Write a script to print all the words in the given array that can be types +# using alphabet on only one row of the keyboard. +# Let us assume the keys are arranged as below: +# Row 1: qwertyuiop +# Row 2: asdfghjkl +# Row 3: zxcvbnm +# +# Example 1 Input: @words = ("Hello","Alaska","Dad","Peace") +# Output: ("Alaska","Dad") +# Example 2 Input: @array = ("OMG","Bye") +# Output: () +#============================================================================= + +use v5.36; + +no warnings "experimental::builtin"; +use builtin qw/trim/; + +use List::Util qw/any/; + + +use Getopt::Long; +my $DoTest = 0; + +GetOptions("test" => \$DoTest); +exit(!runTest()) if $DoTest; + +say "(", join(", ", map { qq("$_") } keyboardWord(\@ARGV)->@*), ")"; + + +sub isKeyboardWord($word) +{ +state @Keyboard = ( qr/[qwertyuiop]+/, qr/[asdfghjkl]+/, qr/[zxcvbnm]+/ ); + return any { $word =~ /\A$_\Z/ } @Keyboard; +} + +sub keyboardWord($list) +{ + my @result = grep { isKeyboardWord(lc trim $_) } $list->@*; + return \@result; +} + +sub runTest +{ + use Test2::V0; + + is( keyboardWord([qw(Hello Alaska Dad Peace)]), [qw(Alaska Dad)], "Example 1"); + is( keyboardWord([qw(OMG Bye)]), [qw()], "Example 2"); + + done_testing; +} + -- cgit From 9d6384646870b277c64dec757178d07eabbe3423 Mon Sep 17 00:00:00 2001 From: Peter Campbell Smith Date: Mon, 6 Mar 2023 15:58:42 +0000 Subject: This is week 207 --- challenge-207/peter-campbell-smith/blog.txt | 1 + challenge-207/peter-campbell-smith/perl/ch-1.pl | 32 +++++++++++++++++++++++ challenge-207/peter-campbell-smith/perl/ch-2.pl | 34 +++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 challenge-207/peter-campbell-smith/blog.txt create mode 100755 challenge-207/peter-campbell-smith/perl/ch-1.pl create mode 100755 challenge-207/peter-campbell-smith/perl/ch-2.pl diff --git a/challenge-207/peter-campbell-smith/blog.txt b/challenge-207/peter-campbell-smith/blog.txt new file mode 100644 index 0000000000..f095018792 --- /dev/null +++ b/challenge-207/peter-campbell-smith/blog.txt @@ -0,0 +1 @@ +http://ccgi.campbellsmiths.force9.co.uk/challenge/207/1 diff --git a/challenge-207/peter-campbell-smith/perl/ch-1.pl b/challenge-207/peter-campbell-smith/perl/ch-1.pl new file mode 100755 index 0000000000..e8308e39ad --- /dev/null +++ b/challenge-207/peter-campbell-smith/perl/ch-1.pl @@ -0,0 +1,32 @@ +#!/usr/bin/perl + +# Peter Campbell Smith - 2023-02-20 + +use v5.28; +use utf8; +use warnings; + +# We are given an array of words and asked to write a script to print all the words in the +# array that can be typed using the letters on only one row of the keyboard. + +# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge/207/1 + +linear_words('Hello','Alaska','Dad','Peace'); +linear_words('OMG','Bye'); +linear_words('typewriter', 'zmncbxvz', 'shakalshas'); +linear_words(qw[We are given an array of words and asked to write a script to print all the words in the + array that can be typed using the letters on only one row of the keyboard]); + +sub linear_words { + + my (@test, $word, $result); + $result = ''; + + # loop over words and save those that are monolinear + for $word (@_) { + $result .= qq['$word', ] if $word =~ m¦^([qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$¦i; + } + + say qq[\nInput: ('] . join(q[', '], @_) . qq[')]; + say qq[Output: (] . substr($result, 0, -2) . qq[)]; +} diff --git a/challenge-207/peter-campbell-smith/perl/ch-2.pl b/challenge-207/peter-campbell-smith/perl/ch-2.pl new file mode 100755 index 0000000000..724f9ac8f2 --- /dev/null +++ b/challenge-207/peter-campbell-smith/perl/ch-2.pl @@ -0,0 +1,34 @@ +#!/usr/bin/perl + +# Peter Campbell Smith - 2023-02-20 + +use v5.28; +use utf8; +use warnings; + +# We are given a list of the number of citations a researcher has received +# for each of his published papers, ordered from most cited to least. +# We are asked to write a script to compute the researcher’s H-index, which is the maximum n +# where the n'th number in the list is at least n. + +# Blog: http://ccgi.campbellsmiths.force9.co.uk/challenge/207/2 + +h_index(10, 8, 5, 4, 3); +h_index(25, 8, 5, 3, 3); +h_index(10, 9, 8, 7, 6, 5, 4, 3, 2, 1); +h_index(0); +h_index(); +h_index(4, 4, 4, 4); + +sub h_index { + + my (@list, $j); + + # loop over list (0-based!) to find first where n'th number in list < $n + @list = @_; + for ($j = 0; $j < scalar @list; $j ++) { + last unless $list[$j] >= $j + 1; + } + say qq[\nInput: \@citations = (] . join(', ', @list) . + qq[)\nOutput: $j]; +} -- cgit From b99fe695d5645957b03f50697ecb5b2affe193d3 Mon Sep 17 00:00:00 2001 From: Luis Mochan Date: Mon, 6 Mar 2023 10:10:10 -0600 Subject: Solve PWC207 --- challenge-207/wlmb/blog.txt | 2 ++ challenge-207/wlmb/perl/ch-1.pl | 12 ++++++++++++ challenge-207/wlmb/perl/ch-2.pl | 12 ++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 challenge-207/wlmb/blog.txt create mode 100755 challenge-207/wlmb/perl/ch-1.pl create mode 100755 challenge-207/wlmb/perl/ch-2.pl diff --git a/challenge-207/wlmb/blog.txt b/challenge-207/wlmb/blog.txt new file mode 100644 index 0000000000..a505d8681e --- /dev/null +++ b/challenge-207/wlmb/blog.txt @@ -0,0 +1,2 @@ +https://wlmb.github.io/2023/03/06/PWC207/ + diff --git a/challenge-207/wlmb/perl/ch-1.pl b/challenge-207/wlmb/perl/ch-1.pl new file mode 100755 index 0000000000..c21d841bea --- /dev/null +++ b/challenge-207/wlmb/perl/ch-1.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# Perl weekly challenge 207 +# Task 1: Keyboard Word +# +# See https://wlmb.github.io/2023/03/06/PWC207/#task-1-keyboard-word +use v5.36; +die <<~"FIN" unless @ARGV; + Usage: $0 W1 [W2...] + to find which of the words W1 W2... may be written using a single keyboard row. + FIN +say join " ", @ARGV, "->", + grep {/^([qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$/i} @ARGV; diff --git a/challenge-207/wlmb/perl/ch-2.pl b/challenge-207/wlmb/perl/ch-2.pl new file mode 100755 index 0000000000..d007b11f81 --- /dev/null +++ b/challenge-207/wlmb/perl/ch-2.pl @@ -0,0 +1,12 @@ +#!/usr/bin/env perl +# Perl weekly challenge 207 +# Task 2: H-Index +# +# See https://wlmb.github.io/2023/03/06/PWC207/#task-2-h-index +use v5.36; +my $h=0; +for(sort{$b<=>$a}@ARGV){ + last if $_<=$h; + ++$h +} +say join " ", @ARGV, "->", $h; -- cgit From 5da3c4efe8be89a6298831a6ae9a28dbacd5df3b Mon Sep 17 00:00:00 2001 From: Paulo Custodio Date: Mon, 6 Mar 2023 19:02:28 +0000 Subject: Add Perl, C, C++ and Forth solutions --- challenge-207/paulo-custodio/Makefile | 2 + challenge-207/paulo-custodio/basic/ch-1.bas | 59 ++++++++++++++++++++ challenge-207/paulo-custodio/basic/ch-2.bas | 70 ++++++++++++++++++++++++ challenge-207/paulo-custodio/c/ch-1.c | 67 +++++++++++++++++++++++ challenge-207/paulo-custodio/c/ch-2.c | 61 +++++++++++++++++++++ challenge-207/paulo-custodio/cpp/ch-1.cpp | 59 ++++++++++++++++++++ challenge-207/paulo-custodio/cpp/ch-2.cpp | 54 ++++++++++++++++++ challenge-207/paulo-custodio/forth/ch-1.fs | 85 +++++++++++++++++++++++++++++ challenge-207/paulo-custodio/forth/ch-2.fs | 78 ++++++++++++++++++++++++++ challenge-207/paulo-custodio/perl/ch-1.pl | 45 +++++++++++++++ challenge-207/paulo-custodio/perl/ch-2.pl | 47 ++++++++++++++++ challenge-207/paulo-custodio/t/test-1.yaml | 5 ++ challenge-207/paulo-custodio/t/test-2.yaml | 15 +++++ 13 files changed, 647 insertions(+) create mode 100644 challenge-207/paulo-custodio/Makefile create mode 100644 challenge-207/paulo-custodio/basic/ch-1.bas create mode 100644 challenge-207/paulo-custodio/basic/ch-2.bas create mode 100644 challenge-207/paulo-custodio/c/ch-1.c create mode 100644 challenge-207/paulo-custodio/c/ch-2.c create mode 100644 challenge-207/paulo-custodio/cpp/ch-1.cpp create mode 100644 challenge-207/paulo-custodio/cpp/ch-2.cpp create mode 100644 challenge-207/paulo-custodio/forth/ch-1.fs create mode 100644 challenge-207/paulo-custodio/forth/ch-2.fs create mode 100644 challenge-207/paulo-custodio/perl/ch-1.pl create mode 100644 challenge-207/paulo-custodio/perl/ch-2.pl create mode 100644 challenge-207/paulo-custodio/t/test-1.yaml create mode 100644 challenge-207/paulo-custodio/t/test-2.yaml diff --git a/challenge-207/paulo-custodio/Makefile b/challenge-207/paulo-custodio/Makefile new file mode 100644 index 0000000000..c3c762d746 --- /dev/null +++ b/challenge-207/paulo-custodio/Makefile @@ -0,0 +1,2 @@ +all: + perl ../../challenge-001/paulo-custodio/test.pl diff --git a/challenge-207/paulo-custodio/basic/ch-1.bas b/challenge-207/paulo-custodio/basic/ch-1.bas new file mode 100644 index 0000000000..d5f8593713 --- /dev/null +++ b/challenge-207/paulo-custodio/basic/ch-1.bas @@ -0,0 +1,59 @@ +' Challenge 207 +' +' Task 1: Keyboard Word +' Submitted by: Mohammad S Anwar +' +' You are given an array of words. +' +' Write a script to print all the words in the given array that can be types +' using alphabet on only one row of the keyboard. +' +' Let us assume the keys are arranged as below: +' +' Row 1: qwertyuiop +' Row 2: asdfghjkl +' Row 3: zxcvbnm +' +' Example 1 +' +' Input: @words = ("Hello","Alaska","Dad","Peace") +' Output: ("Alaska","Dad") +' +' Example 2 +' +' Input: @array = ("OMG","Bye") +' Output: () + +function remove_char(byval s as string, c as string) as string + dim p as integer + + p=instr(s,c) + do while p>0 + s=left(s,p-1)+mid(s,p+1) + p=instr(s,c) + loop + remove_char=s +end function + +function can_type_word(k as string, byval s as string) as boolean + dim i as integer + for i=1 to len(k) + s=remove_char(s,mid(k,i,1)) + next + can_type_word=s="" +end function + +function can_type(s as string) as boolean + s=lcase(s) + can_type=can_type_word("qwertyuiop",s) or _ + can_type_word("asdfghjkl",s) or _ + can_type_word("zxcvbnm",s) +end function + +dim i as integer +i=1 +do while command(i)<>"" + if can_type(command(i)) then print command(i);" "; + i=i+1 +loop +print diff --git a/challenge-207/paulo-custodio/basic/ch-2.bas b/challenge-207/paulo-custodio/basic/ch-2.bas new file mode 100644 index 0000000000..2e2dfae944 --- /dev/null +++ b/challenge-207/paulo-custodio/basic/ch-2.bas @@ -0,0 +1,70 @@ +' Challenge 207 +' +' Task 2: H-Index +' Submitted by: Mohammad S Anwar +' +' You are given an array of integers containing citations a researcher has +' received for each paper. +' +' Write a script to compute the researcher’s H-Index. For more information +' please checkout the wikipedia page. +' +' The H-Index is the largest number h such that h articles have at least h +' citations each. For example, if an author has five publications, +' with 9, 7, 6, 2, and 1 citations (ordered from greatest to least), +' then the author’s h-index is 3, because the author has three publications +' with 3 or more citations. However, the author does not have four +' publications with 4 or more citations. +' +' +' Example 1 +' +' Input: @citations = (10,8,5,4,3) +' Output: 4 +' +' Because the 4th publication has 4 citations and the 5th has only 3. +' +' Example 2 +' +' Input: @citations = (25,8,5,3,3) +' Output: 3 +' +' The H-Index is 3 because the fourth paper has only 3 citations. + +sub collect_args(nums() as integer) + dim i as integer + i=0 + do while command(i+1)<>"" + redim preserve nums(i) as integer + nums(i)=val(command(i+1)) + i=i+1 + loop +end sub + +sub rsort(mins() as integer) + dim i as integer, j as integer, n as integer + + for i=lbound(mins) to ubound(mins)-1 + for j=i+1 to ubound(mins) + if mins(i) +#include +#include +#include +#include + +void remove_char(char* word, int ch) { + char* p; + while ((p = strchr(word, ch)) != NULL) { + memmove(p, p+1, strlen(p+1)+1); // copy also null char + } +} + +bool can_type_word(const char* keys, const char* word_) { + char word[MAX_WORD]; + assert(strlen(word_) < MAX_WORD); + strcpy(word, word_); + for (char* p = word; *p != '\0'; p++) + *p = tolower(*p); + for (const char* p = keys; *p != '\0'; p++) + remove_char(word, tolower(*p)); + return word[0] == '\0'; +} + +bool can_type(const char* word) { + return can_type_word("qwertyuiop", word) || + can_type_word("asdfghjkl", word) || + can_type_word("zxcvbnm", word); +} + +int main(int argc, char* argv[]) { + argv++; argc--; + for (int i = 0; i < argc; i++) + if (can_type(argv[i])) + printf("%s ", argv[i]); + printf("\n"); +} diff --git a/challenge-207/paulo-custodio/c/ch-2.c b/challenge-207/paulo-custodio/c/ch-2.c new file mode 100644 index 0000000000..c051a6100f --- /dev/null +++ b/challenge-207/paulo-custodio/c/ch-2.c @@ -0,0 +1,61 @@ +/* +Challenge 207 + +Task 2: H-Index +Submitted by: Mohammad S Anwar + +You are given an array of integers containing citations a researcher has +received for each paper. + +Write a script to compute the researcher’s H-Index. For more information +please checkout the wikipedia page. + + The H-Index is the largest number h such that h articles have at least h + citations each. For example, if an author has five publications, + with 9, 7, 6, 2, and 1 citations (ordered from greatest to least), + then the author’s h-index is 3, because the author has three publications + with 3 or more citations. However, the author does not have four + publications with 4 or more citations. + + +Example 1 + +Input: @citations = (10,8,5,4,3) +Output: 4 + +Because the 4th publication has 4 citations and the 5th has only 3. + +Example 2 + +Input: @citations = (25,8,5,3,3) +Output: 3 + +The H-Index is 3 because the fourth paper has only 3 citations. +*/ + +#define MAX_ARTICLES 256 + +int articles[MAX_ARTICLES]; + +#include +#include +#include + +int compare(const void* a, const void* b) { + return *(int*)b - *(int*)a; +} + +int h_index(int articles[], int num_articles) { + qsort(articles, num_articles, sizeof(int), compare); + for (int i = 0; i < num_articles; i++) + if (articles[i] < i+1) + return i+1-1; + return -1; +} + +int main(int argc, char* argv[]) { + argv++; argc--; + for (int i = 0; i < argc; i++) + articles[i] = atoi(argv[i]); + printf("%d\n", h_index(articles, argc)); +} diff --git a/challenge-207/paulo-custodio/cpp/ch-1.cpp b/challenge-207/paulo-custodio/cpp/ch-1.cpp new file mode 100644 index 0000000000..f8c8738239 --- /dev/null +++ b/challenge-207/paulo-custodio/cpp/ch-1.cpp @@ -0,0 +1,59 @@ +/* +Challenge 207 + +Task 1: Keyboard Word +Submitted by: Mohammad S Anwar + +You are given an array of words. + +Write a script to print all the words in the given array that can be types +using alphabet on only one row of the keyboard. + +Let us assume the keys are arranged as below: + +Row 1: qwertyuiop +Row 2: asdfghjkl +Row 3: zxcvbnm + +Example 1 + +Input: @words = ("Hello","Alaska","Dad","Peace") +Output: ("Alaska","Dad") + +Example 2 + +Input: @array = ("OMG","Bye") +Output: () +*/ + +#include +#include +#include +#include + +void remove_char(std::string& word, int ch) { + word.erase(std::remove(word.begin(), word.end(), tolower(ch)), word.end()); +} + +bool can_type_word(const std::string& keys, const std::string& word_) { + std::string word; + for (auto& ch : word_) + word.push_back(tolower(ch)); + for (auto& ch : keys) + remove_char(word, tolower(ch)); + return word.size() == 0; +} + +bool can_type(const std::string& word) { + return can_type_word("qwertyuiop", word) || + can_type_word("asdfghjkl", word) || + can_type_word("zxcvbnm", word); +} + +int main(int argc, char* argv[]) { + argv++; argc--; + for (int i = 0; i < argc; i++) + if (can_type(argv[i])) + std::cout << argv[i]; + std::cout << std::endl; +} diff --git a/challenge-207/paulo-custodio/cpp/ch-2.cpp b/challenge-207/paulo-custodio/cpp/ch-2.cpp new file mode 100644 index 0000000000..79ebd8ea8e --- /dev/null +++ b/challenge-207/paulo-custodio/cpp/ch-2.cpp @@ -0,0 +1,54 @@ +/* +Challenge 207 + +Task 2: H-Index +Submitted by: Mohammad S Anwar + +You are given an array of integers containing citations a researcher has +received for each paper. + +Write a script to compute the researcher’s H-Index. For more information +please checkout the wikipedia page. + + The H-Index is the largest number h such that h articles have at least h + citations each. For example, if an author has five publications, + with 9, 7, 6, 2, and 1 citations (ordered from greatest to least), + then the author’s h-index is 3, because the author has three publications + with 3 or more citations. However, the author does not have four + publications with 4 or more citations. + + +Example 1 + +Input: @citations = (10,8,5,4,3) +Output: 4 + +Because the 4th publication has 4 citations and the 5th has only 3. + +Example 2 + +Input: @citations = (25,8,5,3,3) +Output: 3 + +The H-Index is 3 because the fourth paper has only 3 citations. +*/ + +#include +#include +#include + +int h_index(std::vector& articles) { + std::sort(articles.rbegin(), articles.rend()); + for (size_t i = 0; i < articles.size(); i++) + if (articles[i] < i+1) + return i+1-1; + return -1; +} + +int main(int argc, char* argv[]) { + argv++; argc--; + std::vector articles; + for (int i = 0; i < argc; i++) + articles.push_back(atoi(argv[i])); + std::cout << h_index(articles) << std::endl; +} diff --git a/challenge-207/paulo-custodio/forth/ch-1.fs b/challenge-207/paulo-custodio/forth/ch-1.fs new file mode 100644 index 0000000000..095c3b20a2 --- /dev/null +++ b/challenge-207/paulo-custodio/forth/ch-1.fs @@ -0,0 +1,85 @@ +#! /usr/bin/env gforth + +\ Challenge 207 +\ +\ Task 1: Keyboard Word +\ Submitted by: Mohammad S Anwar +\ +\ You are given an array of words. +\ +\ Write a script to print all the words in the given array that can be types +\ using alphabet on only one row of the keyboard. +\ +\ Let us assume the keys are arranged as below: +\ +\ Row 1: qwertyuiop +\ Row 2: asdfghjkl +\ Row 3: zxcvbnm +\ +\ Example 1 +\ +\ Input: @words = ("Hello","Alaska","Dad","Peace") +\ Output: ("Alaska","Dad") +\ +\ Example 2 +\ +\ Input: @array = ("OMG","Bye") +\ Output: () + + +\ copy text to counted string, convert to upper case +: copy_text { addr-from len addr-to -- } + len 0 ?DO + addr-from I + C@ TOUPPER + addr-to 1+ I + C! + LOOP + len addr-to C! +; + +\ remove char from text +CREATE remove_char_ch 1 ALLOT +: remove_char { addr-cstr ch -- } + ch TOUPPER remove_char_ch C! + BEGIN + addr-cstr COUNT remove_char_ch 1 SEARCH \ while char is found + WHILE + { rest-addr rest-len } + rest-addr 1+ rest-addr rest-len CMOVE + addr-cstr C@ 1- addr-cstr C! + REPEAT + 2DROP +; + +\ check if word can be typed with chars +CREATE check_text 256 ALLOT +: can_type_word { addr-keys len-keys addr-text len-text -- } + addr-text len-text check_text copy_text \ make a copy + len-keys 0 ?DO + addr-keys I + C@ ( key ) + check_text SWAP remove_char + LOOP + check_text C@ 0= \ true if empty +; + +\ check if word can by typed with one row of the keyboard +: can_type { addr-text len-text -- } + S" qwertyuiop" addr-text len-text can_type_word + S" asdfghjkl" addr-text len-text can_type_word OR + S" zxcvbnm" addr-text len-text can_type_word OR +; + +\ check all command line words +: task ( -- ) + BEGIN NEXT-ARG DUP WHILE + 2DUP can_type IF + TYPE SPACE + ELSE + 2DROP + ENDIF + REPEAT + 2DROP + CR +; + +task +BYE diff --git a/challenge-207/paulo-custodio/forth/ch-2.fs b/challenge-207/paulo-custodio/forth/ch-2.fs new file mode 100644 index 0000000000..51ac744491 --- /dev/null +++ b/challenge-207/paulo-custodio/forth/ch-2.fs @@ -0,0 +1,78 @@ +\ Challenge 207 +\ +\ Task 2: H-Index +\ Submitted by: Mohammad S Anwar +\ +\ You are given an array of integers containing citations a researcher has +\ received for each paper. +\ +\ Write a script to compute the researcher’s H-Index. For more information +\ please checkout the wikipedia page. +\ +\ The H-Index is the largest number h such that h articles have at least h +\ citations each. For example, if an author has five publications, +\ with 9, 7, 6, 2, and 1 citations (ordered from greatest to least), +\ then the author’s h-index is 3, because the author has three publications +\ with 3 or more citations. However, the author does not have four +\ publications with 4 or more citations. +\ +\ +\ Example 1 +\ +\ Input: @citations = (10,8,5,4,3) +\ Output: 4 +\ +\ Because the 4th publication has 4 citations and the 5th has only 3. +\ +\ Example 2 +\ +\ Input: @citations = (25,8,5,3,3) +\ Output: 3 +\ +\ The H-Index is 3 because the fourth paper has only 3 citations. + +CREATE citations 256 CELLS ALLOT +0 VALUE num_citations + +: citation[] ( i -- addr ) + CELLS citations + +; + +: collect_args ( -- ) + BEGIN NEXT-ARG DUP WHILE + 0 0 2SWAP >NUMBER 2DROP DROP + num_citations citation[] ! + num_citations 1+ TO num_citations + REPEAT + 2DROP +; + +\ reverse sort array of integers +: rsort ( -- ) + num_citations 0> IF + num_citations 1- 0 ?DO + num_citations I 1+ ?DO + J citation[] @ + I citation[] @ + < IF + J citation[] @ I citation[] @ J citation[] ! I citation[] ! + THEN + LOOP + LOOP + THEN +; + +\ H-index +: h_index ( -- n ) + -1 + num_citations 0 ?DO + I citation[] @ I 1+ < IF + DROP I LEAVE + THEN + LOOP +; + +collect_args +rsort +h_index . CR +BYE diff --git a/challenge-207/paulo-custodio/perl/ch-1.pl b/challenge-207/paulo-custodio/perl/ch-1.pl new file mode 100644 index 0000000000..30b23a1f46 --- /dev/null +++ b/challenge-207/paulo-custodio/perl/ch-1.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +# Challenge 207 +# +# Task 1: Keyboard Word +# Submitted by: Mohammad S Anwar +# +# You are given an array of words. +# +# Write a script to print all the words in the given array that can be types +# using alphabet on only one row of the keyboard. +# +# Let us assume the keys are arranged as below: +# +# Row 1: qwertyuiop +# Row 2: asdfghjkl +# Row 3: zxcvbnm +# +# Example 1 +# +# Input: @words = ("Hello","Alaska","Dad","Peace") +# Output: ("Alaska","Dad") +# +# Example 2 +# +# Input: @array = ("OMG","Bye") +# Output: () + +use Modern::Perl; +use List::Util qw( any ); + +my @keys = qw( qwertyuiop asdfghjkl zxcvbnm ); + +sub can_type_word { + my($word) = @_; + $word =~ s/\W//g; + return any {($word =~ s/[$_]//gir) eq ""} @keys; +} + +sub can_type { + my(@words) = @_; + return grep {can_type_word($_)} @words; +} + +say join(" ", can_type(@ARGV)); diff --git a/challenge-207/paulo-custodio/perl/ch-2.pl b/challenge-207/paulo-custodio/perl/ch-2.pl new file mode 100644 index 0000000000..b02cda55fe --- /dev/null +++ b/challenge-207/paulo-custodio/perl/ch-2.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +# Challenge 207 +# +# Task 2: H-Index +# Submitted by: Mohammad S Anwar +# +# You are given an array of integers containing citations a researcher has +# received for each paper. +# +# Write a script to compute the researcher’s H-Index. For more information +# please checkout the wikipedia page. +# +# The H-Index is the largest number h such that h articles have at least h +# citations each. For example, if an author has five publications, +# with 9, 7, 6, 2, and 1 citations (ordered from greatest to least), +# then the author’s h-index is 3, because the author has three publications +# with 3 or more citations. However, the author does not have four +# publications with 4 or more citations. +# +# +# Example 1 +# +# Input: @citations = (10,8,5,4,3) +# Output: 4 +# +# Because the 4th publication has 4 citations and the 5th has only 3. +# +# Example 2 +# +# Input: @citations = (25,8,5,3,3) +# Output: 3 +# +# The H-Index is 3 because the fourth paper has only 3 citations. + +use Modern::Perl; + +sub h_index { + my(@citations) = @_; + @citations = sort {$b<=>$a} @citations; # sort descending + for my $h (1 .. @citations) { + return $h-1 if $citations[$h-1] < $h; + } + die; +} + +say h_index(@ARGV); diff --git a/challenge-207/paulo-custodio/t/test-1.yaml b/challenge-207/paulo-custodio/t/test-1.yaml new file mode 100644 index 0000000000..816bf79e37 --- /dev/null +++ b/challenge-207/paulo-custodio/t/test-1.yaml @@ -0,0 +1,5 @@ +- setup: + cleanup: + args: Hello Alaska Dad Peace + input: + output: Alaska Dad diff --git a/challenge-207/paulo-custodio/t/test-2.yaml b/challenge-207/paulo-custodio/t/test-2.yaml new file mode 100644 index 0000000000..6c231c3d62 --- /dev/null +++ b/challenge-207/paulo-custodio/t/test-2.yaml @@ -0,0 +1,15 @@ +- setup: + cleanup: + args: 10 8 5 4 3 + input: + output: 4 +- setup: + cleanup: + args: 25 8 5 3 3 + input: + output: 3 +- setup: + cleanup: + args: 3 4 5 8 10 + input: + output: 4 -- cgit From fec8edfe431599a9917ebcbb8072f15fe47704a5 Mon Sep 17 00:00:00 2001 From: CY Fung Date: Tue, 7 Mar 2023 06:25:12 +0800 Subject: Week 207 --- challenge-207/cheok-yin-fung/perl/ch-1.pl | 50 +++++++++++++++++++++++++++++++ challenge-207/cheok-yin-fung/perl/ch-2.pl | 20 +++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 challenge-207/cheok-yin-fung/perl/ch-1.pl create mode 100644 challenge-207/cheok-yin-fung/perl/ch-2.pl diff --git a/challenge-207/cheok-yin-fung/perl/ch-1.pl b/challenge-207/cheok-yin-fung/perl/ch-1.pl new file mode 100644 index 0000000000..a30764252b --- /dev/null +++ b/challenge-207/cheok-yin-fung/perl/ch-1.pl @@ -0,0 +1,50 @@ +# The Weekly Challenge 207 +# Task 1 Keyboard Word +use v5.30.0; +use warnings; +use List::Util qw/uniq/; + +sub kw { + my @row = ("qwertyuiop", "asdfghjkl", "zxcvbnm"); + my @_row = map {join "", sort {$a cmp $b} split "", $_} @row; + + my @ans; + my @words = @_; + foreach my $word (@words) { + my $_word = join "", uniq sort {$a cmp $b} split "", lc $word; + push @ans, $word if subseq($_row[0], $_word); + push @ans, $word if subseq($_row[1], $_word); + push @ans, $word if subseq($_row[2], $_word); + } + return @ans; +} + +sub subseq { + # @mseq and @sseq are with distinct elements, + # and sorted in the same way + my $valid; + my @mseq = split "", $_[0]; + my @sseq = split "", $_[1]; + my $i = 0; + my $j = 0; + while ($j < scalar @sseq) { + if ($sseq[$j] lt $mseq[$i]) { + $valid = 0; + last; + } + if ($sseq[$j] eq $mseq[$i]) { + $j++; + $i++; + $valid = 1; + } + last if $j > $#sseq || $i > $#mseq; + $i++ if $sseq[$j] gt $mseq[$i]; + last if $i > $#mseq; + } + return 1 if $valid && $j == 1+$#sseq && $i <= 1+$#mseq; + return 0; +} + + + +say join " ", kw("Hello","Alaska","Dad","Peace", "OMG", "Bye"); diff --git a/challenge-207/cheok-yin-fung/perl/ch-2.pl b/challenge-207/cheok-yin-fung/perl/ch-2.pl new file mode 100644 index 0000000000..16c9c8ede0 --- /dev/null +++ b/challenge-207/cheok-yin-fung/perl/ch-2.pl @@ -0,0 +1,20 @@ +# The Weekly Challenge 207 +# Task 2 H-Index +use v5.30.0; +use warnings; + +sub hi { + my @citations = @_; + @citations = sort {$b<=>$a} @citations; + $i = 0; + while ($i <= $#citations && $citations[$i] >= $i+1) { + $i++ + } + return $i; +} + +use Test::More tests=>4; +ok hi(10,8,5,4,3) == 4; +ok hi(25,8,5,3,3) == 3; +ok hi(25) == 1; +ok hi(2) == 1; -- cgit From 9efae9f67fef43a2f051653597012f51c11c73b6 Mon Sep 17 00:00:00 2001 From: "E. Choroba" Date: Mon, 6 Mar 2023 23:36:07 +0100 Subject: Add solutions to 207: Keyboard Word & H-Index by E. Choroba --- challenge-207/e-choroba/perl/ch-1.pl | 24 ++++++++++++++++++++++++ challenge-207/e-choroba/perl/ch-2.pl | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 challenge-207/e-choroba/perl/ch-1.pl create mode 100755 challenge-207/e-choroba/perl/ch-2.pl diff --git a/challenge-207/e-choroba/perl/ch-1.pl b/challenge-207/e-choroba/perl/ch-1.pl new file mode 100755 index 0000000000..51a1cc6175 --- /dev/null +++ b/challenge-207/e-choroba/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental 'signatures'; + +my $i = 0; +my %ROW = map { ++$i; map { $_ => $i } split // } + qw( qwertyuiop asdfghjkl zxcvbnm ); + +sub keyboard_word(@words) { + return [grep is_single_row($_), @words] +} + +sub is_single_row($word) { + my %rows; + @rows{ @ROW{ split //, lc $word } } = (); + return 1 == keys %rows +} + +use Test2::V0; +plan 2; + +is keyboard_word(qw( Hello Alaska Dad Peace )), [qw[ Alaska Dad ]], 'Example 1'; +is keyboard_word(qw( OMG Bye )), [], 'Example 2'; diff --git a/challenge-207/e-choroba/perl/ch-2.pl b/challenge-207/e-choroba/perl/ch-2.pl new file mode 100755 index 0000000000..09343f121f --- /dev/null +++ b/challenge-207/e-choroba/perl/ch-2.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +use warnings; +use strict; +use experimental 'signatures'; + +sub h_index(@citations) { + @citations = sort { $b <=> $a } @citations; + push @citations, -1; + for my $i (0 .. $#citations) { + return $i if $citations[$i] < $i + 1; + } +} + +use Test::More tests => 2 + 3; + +is h_index(10, 8, 5, 4, 3), 4, 'Example 1'; +is h_index(25, 8, 5, 3, 3), 3, 'Example 2'; + +is h_index(9, 7, 6, 2, 1), 3, 'Wikipedia'; +is h_index(100), 1, 'Single publication'; +is h_index(1, 1, 1, 1), 1, 'All ones'; -- cgit From 4dddd9deec2a56bd8ff9372413fdf84240aa191c Mon Sep 17 00:00:00 2001 From: Dave Jacoby Date: Mon, 6 Mar 2023 18:01:08 -0500 Subject: #207 DAJ --- challenge-207/dave-jacoby/blog.txt | 1 + challenge-207/dave-jacoby/perl/ch-1.pl | 42 ++++++++++++++++++++++++++++++++++ challenge-207/dave-jacoby/perl/ch-2.pl | 31 +++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 challenge-207/dave-jacoby/blog.txt create mode 100644 challenge-207/dave-jacoby/perl/ch-1.pl create mode 100644 challenge-207/dave-jacoby/perl/ch-2.pl diff --git a/challenge-207/dave-jacoby/blog.txt b/challenge-207/dave-jacoby/blog.txt new file mode 100644 index 0000000000..5ad094dd9f --- /dev/null +++ b/challenge-207/dave-jacoby/blog.txt @@ -0,0 +1 @@ +https://jacoby.github.io/2023/03/06/multistatus-weekly-challenge-207.html diff --git a/challenge-207/dave-jacoby/perl/ch-1.pl b/challenge-207/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..acfd7f006c --- /dev/null +++ b/challenge-207/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,42 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ fc say postderef signatures state }; + +use DateTime; + +my @examples = ( + + [qw{ Hello Alaska Dad Peace }], + [qw{ OMG Bye }], +); + +for my $e (@examples) { + my $list = join ',', map { qq{"$_"} } $e->@*; + my $out = keyboard_word( $e->@* ); + my $olist = join ',', map { qq{"$_"} } $out->@*; + say <<"END"; + Input: \@array = ($list) + Output: ($olist) +END +} + +sub keyboard_word ( @array ) { + my @output; + my %row_1 = map { $_ => 1 } split //, 'qwertyuiop'; + my %row_2 = map { $_ => 1 } split //, 'asdfghjkl'; + my %row_3 = map { $_ => 1 } split //, 'zxcvbnm'; + + for my $Word (@array) { + my $count; + for my $l ( map { fc $_ } split //, $Word ) { + $count->{1}++ if $row_1{$l}; + $count->{2}++ if $row_2{$l}; + $count->{3}++ if $row_3{$l}; + } + push @output, $Word unless scalar keys $count->%* > 1; + } + return wantarray ? @output : \@output; +} + diff --git a/challenge-207/dave-jacoby/perl/ch-2.pl b/challenge-207/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..3d7af432e1 --- /dev/null +++ b/challenge-207/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,31 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ say postderef signatures state }; + +use List::Util qw{ max }; + +my @examples = ( + + [ 10, 8, 5, 4, 3 ], + [ 25, 8, 5, 3, 3 ], +); + +for my $e (@examples) { + my $o = h_index( $e->@* ); + my $array = join ', ', $e->@*; + say <<"END"; + Input: \@array = $array + Output: $o +END +} + +sub h_index ( @citations ) { + my $max = max @citations; + for my $h ( 1 .. $max ) { + my $i = () = grep { $_ >= $h } @citations; + return $h - 1 if $i < $h; + } + return 0; +} -- cgit From 15567a7f4f11d04f5ae8e9d1d4dc9c92b6e1c8e2 Mon Sep 17 00:00:00 2001 From: boblied Date: Mon, 6 Mar 2023 17:23:59 -0600 Subject: Week 207 Task 2 --- challenge-207/bob-lied/perl/ch-2.pl | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 challenge-207/bob-lied/perl/ch-2.pl diff --git a/challenge-207/bob-lied/perl/ch-2.pl b/challenge-207/bob-lied/perl/ch-2.pl new file mode 100644 index 0000000000..027d3aa90f --- /dev/null +++ b/challenge-207/bob-lied/perl/ch-2.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl +# vim:set ts=4 sw=4 sts=4 et ai wm=0 nu: +#============================================================================= +# ch-2.pl Perl Weekly Challenge Week 207 Task 2 H-Index +#============================================================================= +# Copyright (c) 2023, Bob Lied +#============================================================================= +# You are given an array of integers containing citations a researcher has +# received for each paper. +# Write a script to compute the researcher’s H-Index. For more information +# please checkout the wikipedia page. https://en.wikipedia.org/wiki/H-index +# +# The H-Index is the largest number h such that h articles have at least h +# citations each. For example, if an author has five publications, with 9, 7, +# 6, 2, and 1 citations (ordered from greatest to least), then the author’s +# h-index is 3, because the author has three publications with 3 or more +# citations. However, the author does not have four publications with 4 or +# more citations. +# +# Example 1 Input: @citations = (10,8,5,4,3) Output: 4 +# Because the 4th publication has 4 citations and the 5th has only 3. +# Example 2 Input: @citations = (25,8,5,3,3) Output: 3 +# The H-Index is 3 because the fourth paper has only 3 citations. +# +# What this amounts to is finding the largest i in a sorted array such +# that x[i] >= i +#============================================================================= + +use v5.36; + +use List::Util qw/first/; + +use Getopt::Long; +my $Verbose = 0; +my $DoTest = 0; + +GetOptions("test" => \$DoTest, "verbose" => \$Verbose); +exit(!runTest()) if $DoTest; + +say H_index( @ARGV ); + +sub H_index(@cite) +{ + my @sorted = sort { $b <=> $a } @cite; + my $h = first { $sorted[$_] < $_+1 } 0 .. $#sorted; + return $h; +} + +sub runTest +{ + use Test2::V0; + + is( H_index(10,8,5,4,3), 4, "Example 1"); + is( H_index(25,8,5,3,3), 3, "Example 2"); + is( H_index( 1,1,1,1,1), 1, "Example 2"); + + done_testing; +} + -- cgit From eb0c9ee78f1f917e4416def0ee8ec41f40702048 Mon Sep 17 00:00:00 2001 From: boblied Date: Mon, 6 Mar 2023 17:24:13 -0600 Subject: Week 207 blog --- challenge-207/bob-lied/blog.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 challenge-207/bob-lied/blog.txt diff --git a/challenge-207/bob-lied/blog.txt b/challenge-207/bob-lied/blog.txt new file mode 100644 index 0000000000..79de48a164 --- /dev/null +++ b/challenge-207/bob-lied/blog.txt @@ -0,0 +1 @@ +https://dev.to/boblied/pwc-207-im-pickin-up-h-citatations-p0p -- cgit From 143733df58ae683b3ccdd21622b07073ecf7f05a Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Mon, 6 Mar 2023 18:46:55 -0800 Subject: Robbie Hatley's Perl solutions for PWCC 207. --- challenge-207/robbie-hatley/blog.txt | 1 + challenge-207/robbie-hatley/perl/ch-1.pl | 82 ++++++++++++++++++++++++++++++++ challenge-207/robbie-hatley/perl/ch-2.pl | 80 +++++++++++++++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 challenge-207/robbie-hatley/blog.txt create mode 100755 challenge-207/robbie-hatley/perl/ch-1.pl create mode 100755 challenge-207/robbie-hatley/perl/ch-2.pl diff --git a/challenge-207/robbie-hatley/blog.txt b/challenge-207/robbie-hatley/blog.txt new file mode 100644 index 0000000000..b501356b41 --- /dev/null +++ b/challenge-207/robbie-hatley/blog.txt @@ -0,0 +1 @@ +https://hatley-software.blogspot.com/2023/03/robbie-hatleys-perl-solutions-to-weekly_6.html \ No newline at end of file diff --git a/challenge-207/robbie-hatley/perl/ch-1.pl b/challenge-207/robbie-hatley/perl/ch-1.pl new file mode 100755 index 0000000000..bdcfc86b25 --- /dev/null +++ b/challenge-207/robbie-hatley/perl/ch-1.pl @@ -0,0 +1,82 @@ +#! /bin/perl -CSDA + +# This is a 120-character-wide Unicode UTF-8 Perl-source-code text file with hard Unix line breaks ("\x0A"). +# ¡Hablo Español! Говорю Русский. Björt skjöldur. ॐ नमो भगवते वासुदेवाय. 看的星星,知道你是爱。 麦藁雪、富士川町、山梨県。 +# =======|=========|=========|=========|=========|=========|=========|=========|=========|=========|=========|=========| + +######################################################################################################################## +# Robbie Hatley's Perl solution to The Weekly Challege #207-1. +# Written by Robbie Hatley. +# Edit history: +# Mon Mar 06, 2023: Wrote it. +######################################################################################################################## + +=pod + +Task 1: Keyboard Word +Submitted by: Mohammad S Anwar +Write a script to print all the words in a given array that can be typed +using only letters on one row of a QWERTY keyboard: +Row 1: qwertyuiop +Row 2: asdfghjkl +Row 3: zxcvbnm +Example 1: Input: ("Hello","Alaska","Dad","Peace") Output: ("Alaska","Dad") +Example 2: Input: ("OMG","Bye") Output: () + +=cut + +# IO NOTES: +# NOTE: Input is by either built-in array-of-arrays, or @ARGV. If using @ARGV, +# the args should be a space-separated sequence of 'single-quoted' words +# using only letters available on a standard QWERTY keyboard; this +# sequence will be considered to be a single array of words. +# NOTE: Output is to STDOUT and will be those words which can be typed on one +# row of a QWERTY keyboard. + +# PRELIMINARIES: +use v5.36; +use strict; +use warnings; +$"=", "; + +# CPAN MODULES: +use Sys::Binmode; +use List::AllUtils qw( all ); + +# SUBROUTINES: + +sub row($letter){ + if ($letter =~ m/[qwertyuiop]/i ) {return 1} + elsif ($letter =~ m/[asdfghjkl]/i ) {return 2} + elsif ($letter =~ m/[zxcvbnm]/i ) {return 3} + else {return 0}} + +sub one_row($word){ + my @letters = split //,$word; + my $rofl = row($letters[0]); + if (all {row($_) eq $rofl} @letters) {return 1} + else {return 0}} + +# DEFAULT INPUTS: +my @arrays = +( + ['Hello','Alaska','Dad','Peace'], + ['OMG','Bye'], + ['dog','pig','cow','horse','lad','lass'], + ['Bob','Tom','Helen','Sal'], + ['query','fall','you','me','fad'] +); + +# NON-DEFAULT INPUTS: +if (@ARGV) {@arrays = ([@ARGV]);} + +# MAIN BODY OF SCRIPT: +my $t0 = time; +for (@arrays){ + my @array = @{$_}; + my @one_row_words = (); + foreach my $word (@array){ + if (one_row($word)) {push @one_row_words, $word}} + say ''; + say "original word list = (@array)"; + say "one-row words list = (@one_row_words)";} \ No newline at end of