diff options
Diffstat (limited to '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 |
