diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-11 23:18:20 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-11 23:18:20 +0000 |
| commit | 51465a4186e14e5f9ae26e7f5b20dbb9f5ea8aae (patch) | |
| tree | 18d24c852ae719566d8183011215198994991bbe | |
| parent | 4df721aed4edb00a94cbfb390222b3354e01b252 (diff) | |
| parent | 1fa7cf32ff81cd4f85676693185763eccbafe73f (diff) | |
| download | perlweeklychallenge-club-51465a4186e14e5f9ae26e7f5b20dbb9f5ea8aae.tar.gz perlweeklychallenge-club-51465a4186e14e5f9ae26e7f5b20dbb9f5ea8aae.tar.bz2 perlweeklychallenge-club-51465a4186e14e5f9ae26e7f5b20dbb9f5ea8aae.zip | |
Merge pull request #7708 from pip/branch-for-challenge-207
Pip Stuart's submission for challenge-207.
| -rw-r--r-- | challenge-207/pip/perl/ch-1.pl | 40 | ||||
| -rw-r--r-- | challenge-207/pip/perl/ch-2.pl | 26 | ||||
| -rw-r--r-- | challenge-207/pip/raku/ch-1.raku | 40 | ||||
| -rw-r--r-- | challenge-207/pip/raku/ch-2.raku | 26 |
4 files changed, 132 insertions, 0 deletions
diff --git a/challenge-207/pip/perl/ch-1.pl b/challenge-207/pip/perl/ch-1.pl new file mode 100644 index 0000000000..2bc64d9bd0 --- /dev/null +++ b/challenge-207/pip/perl/ch-1.pl @@ -0,0 +1,40 @@ +#!/usr/bin/perl +# HTTPS://TheWeeklyChallenge.Org - Perl/Raku Weekly Challenge #207 - Pip Stuart +# Task1: 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: +# Row1: qwertyuiop +# Row2: asdfghjkl +# Row3: zxcvbnm +# Example1: +# In-put: @words = ("Hello","Alaska","Dad","Peace") +# Output: ( "Alaska","Dad" ) +# Example2: +# In-put: @words = ("OMG","Bye") +# Output: ( ) +use strict;use warnings;use utf8;use v5.12;my $d8VS='N38LGYRO'; +sub KbWd {my @wrdz = @_;my @rwdz = ();my @rowz = ({}, {}, {}); + for (split('', 'qwertyuiop')) { $rowz[0]{$_} = 1; } + for (split('', 'asdfghjkl' )) { $rowz[1]{$_} = 1; } + for (split('', 'zxcvbnm' )) { $rowz[2]{$_} = 1; } + for (@wrdz) {my @lcwd = split('', lc($_));my $airf = 0; + for my $rown (0..2) { + if ( exists($rowz[$rown]{$lcwd[0]})) { $airf = 1; + for my $letr (@lcwd) { # loop thru all of @LowerCasedWorD + if (!exists($rowz[$rown]{$letr })) { $airf = 0; last; } + } # clear AllInRowFlag if any letter is not in the same row + } + } + if ($airf) { push(@rwdz, $_); } + } + printf( "(\"%s\") => ", join('","', @wrdz)); + if (@rwdz) { printf("(\"%s\");\n" , join('","', @rwdz)); } + else { say "();"; } + return(@rwdz); +} +if (@ARGV) { + KbWd(@ARGV); +} else { + KbWd("Hello","Alaska","Dad","Peace"); # => ("Alaska","Dad"); + KbWd("OMG","Bye" ); # => (""); +} diff --git a/challenge-207/pip/perl/ch-2.pl b/challenge-207/pip/perl/ch-2.pl new file mode 100644 index 0000000000..1e2e37c947 --- /dev/null +++ b/challenge-207/pip/perl/ch-2.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +# HTTPS://TheWeeklyChallenge.Org - Perl/Raku Weekly Challenge #207 - Pip Stuart +# Task2: 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. +# Example1: +# In-put: @citations = (10,8,5,4,3) +# Output: 4 Because the 4th publication has 4 citations and the 5th has only 3. +# Example2: +# In-put: @citations = (25,8,5,3,3) +# Output: 3 The H-Index is 3 because the fourth paper has only 3 citations. +# Last date to submit the solution 23:59 (UK Time) Sunday 12th March 2023. +use strict;use warnings;use utf8;use v5.12;my $d8VS='N38LDAYS'; +sub HNdx {my @ctnz = sort { $b <=> $a } @_;my $hndx = 0; + while ($hndx < @ctnz && $ctnz[$hndx] > $hndx) { $hndx++; } + printf("(%-10s) => %d;\n", join(',', @ctnz), $hndx); + return($hndx); +} +if (@ARGV) { + HNdx(@ARGV); +} else { + HNdx(10,8,5,4,3); # => 4; + HNdx(25,8,5,3,3); # => 3; +} diff --git a/challenge-207/pip/raku/ch-1.raku b/challenge-207/pip/raku/ch-1.raku new file mode 100644 index 0000000000..6d9cb7a43f --- /dev/null +++ b/challenge-207/pip/raku/ch-1.raku @@ -0,0 +1,40 @@ +#!/usr/bin/env raku +# HTTPS://TheWeeklyChallenge.Org - Perl/Raku Weekly Challenge #207 - Pip Stuart +# Task1: 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: +# Row1: qwertyuiop +# Row2: asdfghjkl +# Row3: zxcvbnm +# Example1: +# In-put: @words = ("Hello","Alaska","Dad","Peace") +# Output: ( "Alaska","Dad" ) +# Example2: +# In-put: @words = ("OMG","Bye") +# Output: ( ) +use v6;my $d8VS='N39L7wLC'; +sub KbWd {my @wrdz = @_;my @rwdz = ();my @rowz = ({}, {}, {}); + for (split('', 'qwertyuiop', :skip-empty)) { @rowz[0]{$_} = 1; } + for (split('', 'asdfghjkl' , :skip-empty)) { @rowz[1]{$_} = 1; } + for (split('', 'zxcvbnm' , :skip-empty)) { @rowz[2]{$_} = 1; } + for (@wrdz) {my @lcwd = split('', lc($_), :skip-empty);my $airf = 0; + for 0..2 -> $rown { + if ( @rowz[$rown]{@lcwd[0]}:exists ) { $airf = 1; + for @lcwd -> $letr { # loop thru all of @LowerCasedWorD + if (!(@rowz[$rown]{$letr }:exists)) { $airf = 0; last; } + } # clear AllInRowFlag if any letter is not in the same row + } + } + if ($airf) { push(@rwdz, $_); } + } + printf( "(\"%s\") => ", join('","', @wrdz)); + if (@rwdz) { printf("(\"%s\");\n" , join('","', @rwdz)); } + else { say "();"; } + return(@rwdz); +} +if (@*ARGS) { + KbWd(@*ARGS); +} else { + KbWd("Hello","Alaska","Dad","Peace"); # => ("Alaska","Dad"); + KbWd("OMG","Bye" ); # => (""); +} diff --git a/challenge-207/pip/raku/ch-2.raku b/challenge-207/pip/raku/ch-2.raku new file mode 100644 index 0000000000..6dc1ab005a --- /dev/null +++ b/challenge-207/pip/raku/ch-2.raku @@ -0,0 +1,26 @@ +#!/usr/bin/env raku +# HTTPS://TheWeeklyChallenge.Org - Perl/Raku Weekly Challenge #207 - Pip Stuart +# Task2: 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. +# Example1: +# In-put: @citations = (10,8,5,4,3) +# Output: 4 Because the 4th publication has 4 citations and the 5th has only 3. +# Example2: +# In-put: @citations = (25,8,5,3,3) +# Output: 3 The H-Index is 3 because the fourth paper has only 3 citations. +# Last date to submit the solution 23:59 (UK Time) Sunday 12th March 2023. +use v6;my $d8VS='N39L81pR'; +sub HNdx {my @ctnz = sort -*, @_;my $hndx = 0; + while ($hndx < @ctnz.elems && @ctnz[$hndx] > $hndx) { $hndx++; } + printf("(%-10s) => %d;\n", join(',', @ctnz), $hndx); + return($hndx); +} +if (@*ARGS) { + HNdx(@*ARGS); +} else { + HNdx(10,8,5,4,3); # => 4; + HNdx(25,8,5,3,3); # => 3; +} |
