diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-08 21:10:21 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-08 21:10:21 +0000 |
| commit | 35a2d71bf4c57a4db18106b255d3e9c06b5602a4 (patch) | |
| tree | 6e71b0b1abb3a2a264cc03b2a8d9758dcb9e39f2 | |
| parent | ff1ee5bf95fc6d8d8c0aaf40ea82c784c09bb999 (diff) | |
| parent | e828c62a6d5dcb1b26dca191ba08750cb906e602 (diff) | |
| download | perlweeklychallenge-club-35a2d71bf4c57a4db18106b255d3e9c06b5602a4.tar.gz perlweeklychallenge-club-35a2d71bf4c57a4db18106b255d3e9c06b5602a4.tar.bz2 perlweeklychallenge-club-35a2d71bf4c57a4db18106b255d3e9c06b5602a4.zip | |
Merge pull request #7691 from kjetillll/challenge-207-kjetillll
https://theweeklychallenge.org/blog/perl-weekly-challenge-207/
| -rw-r--r-- | challenge-207/kjetillll/perl/ch-1.pl | 17 | ||||
| -rw-r--r-- | challenge-207/kjetillll/perl/ch-2.pl | 29 |
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-207/kjetillll/perl/ch-1.pl b/challenge-207/kjetillll/perl/ch-1.pl new file mode 100644 index 0000000000..42e712888f --- /dev/null +++ b/challenge-207/kjetillll/perl/ch-1.pl @@ -0,0 +1,17 @@ +#https://theweeklychallenge.org/blog/perl-weekly-challenge-207/ +use strict; use warnings; use v5.10; + +sub is_one_row_word { pop =~ /^( [qwertyuiop]+ | [asdfghjkl]+ | [zxcvbnm]+ )$/ix } + +my @test = ( + ["Hello","Alaska","Dad","Peace"], + ["OMG","Bye"] +); + +for ( @ARGV ? ([@ARGV]) : @test ) { + my @input = @$_; + my @output = grep is_one_row_word($_), @input; + say "Input: @input"; + say "Output: @output"; +} + diff --git a/challenge-207/kjetillll/perl/ch-2.pl b/challenge-207/kjetillll/perl/ch-2.pl new file mode 100644 index 0000000000..dfd40082a4 --- /dev/null +++ b/challenge-207/kjetillll/perl/ch-2.pl @@ -0,0 +1,29 @@ + +sub H_index { + @_ = sort { $b <=> $a } @_; #sort input array + pop while $_[-1] < @_; #keep cutting off last elem while its less than array length + return 0+@_ #H-index is now the length of the array +} + +my @test = ( + [10,8,5,4,3], #4 + [25,8,5,3,3], #3 + [10,8,5,5,5], #5 + [25,1,1,1], #1 + [25], #1 +); + +for ( @ARGV ? ([@ARGV]) : @test ) { + my @input = @$_; + printf "Input: %-20s H-Index: %d\n", "@input", H_index(@input); +} + +__END__ + +perl ch-2.pl + +Input: 10 8 5 4 3 H-Index: 4 +Input: 25 8 5 3 3 H-Index: 3 +Input: 10 8 5 5 5 H-Index: 5 +Input: 25 1 1 1 H-Index: 1 +Input: 25 H-Index: 1 |
