diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-08 19:40:37 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 19:40:37 +0000 |
| commit | ca0246441103b7d9adbc017a33b1f16cf31eceb5 (patch) | |
| tree | e773ec981b90383ba687c47e00e311fe563a76df | |
| parent | 181cc0ba08cf9dc76b39d6bd10f5bab63e5253c4 (diff) | |
| parent | 9d6384646870b277c64dec757178d07eabbe3423 (diff) | |
| download | perlweeklychallenge-club-ca0246441103b7d9adbc017a33b1f16cf31eceb5.tar.gz perlweeklychallenge-club-ca0246441103b7d9adbc017a33b1f16cf31eceb5.tar.bz2 perlweeklychallenge-club-ca0246441103b7d9adbc017a33b1f16cf31eceb5.zip | |
Merge pull request #7679 from pjcs00/wk207
This is week 207
| -rw-r--r-- | challenge-207/peter-campbell-smith/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-207/peter-campbell-smith/perl/ch-1.pl | 32 | ||||
| -rwxr-xr-x | challenge-207/peter-campbell-smith/perl/ch-2.pl | 34 |
3 files changed, 67 insertions, 0 deletions
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]; +} |
