diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2023-03-13 08:09:31 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-13 08:09:31 +0000 |
| commit | ea8e553d31c8ded0f54369f1d0df7bf614511bab (patch) | |
| tree | 6e6bdc203a0545e2cb305c9ed6d0058eb161bd11 | |
| parent | b0b11f3efb4cc25de077e3329e41cbcd1687b7b6 (diff) | |
| parent | 8ba1aa77fa03cfad86609f6e0a358969e2c45c0a (diff) | |
| download | perlweeklychallenge-club-ea8e553d31c8ded0f54369f1d0df7bf614511bab.tar.gz perlweeklychallenge-club-ea8e553d31c8ded0f54369f1d0df7bf614511bab.tar.bz2 perlweeklychallenge-club-ea8e553d31c8ded0f54369f1d0df7bf614511bab.zip | |
Merge pull request #7717 from jaldhar/challenge-207
Challenge 207 by Jaldhar H. Vyas.
| -rw-r--r-- | challenge-207/jaldhar-h-vyas/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-207/jaldhar-h-vyas/perl/ch-1.pl | 25 | ||||
| -rwxr-xr-x | challenge-207/jaldhar-h-vyas/perl/ch-2.pl | 14 | ||||
| -rwxr-xr-x | challenge-207/jaldhar-h-vyas/raku/ch-1.raku | 20 | ||||
| -rwxr-xr-x | challenge-207/jaldhar-h-vyas/raku/ch-2.raku | 16 |
5 files changed, 76 insertions, 0 deletions
diff --git a/challenge-207/jaldhar-h-vyas/blog.txt b/challenge-207/jaldhar-h-vyas/blog.txt new file mode 100644 index 0000000000..a140b4b076 --- /dev/null +++ b/challenge-207/jaldhar-h-vyas/blog.txt @@ -0,0 +1 @@ +https://www.braincells.com/perl/2023/03/perl_weekly_challenge_week_207.html
\ No newline at end of file diff --git a/challenge-207/jaldhar-h-vyas/perl/ch-1.pl b/challenge-207/jaldhar-h-vyas/perl/ch-1.pl new file mode 100755 index 0000000000..629cb0503f --- /dev/null +++ b/challenge-207/jaldhar-h-vyas/perl/ch-1.pl @@ -0,0 +1,25 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +sub isSubset { + my @subset = @{$_[0]}; + my %set = map { $_ => 1 } @{$_[1]}; + + return (scalar grep { exists $set{$_} } @subset) == (scalar @subset); +} + +my @rows = map { [split //] } qw/ qwertyuiop asdfghjkl zxcvbnm /; +my @output; + +for my $word (@ARGV) { + my @letters = split //, lc $word; + for my $row (@rows) { + if (isSubset(\@letters, $row)) { + push @output, $word; + last; + } + } +} + +say q{(}, (join q{,}, map { q{"} . $_ . q{"} } @output), q{)}; diff --git a/challenge-207/jaldhar-h-vyas/perl/ch-2.pl b/challenge-207/jaldhar-h-vyas/perl/ch-2.pl new file mode 100755 index 0000000000..4ab8611fb0 --- /dev/null +++ b/challenge-207/jaldhar-h-vyas/perl/ch-2.pl @@ -0,0 +1,14 @@ +#!/usr/bin/perl +use 5.030; +use warnings; + +my $hindex = 0; + +for my $h (1 .. scalar @ARGV) { + if ($ARGV[$h - 1] < $h) { + last; + } + $hindex = $h; +} + +say $hindex; diff --git a/challenge-207/jaldhar-h-vyas/raku/ch-1.raku b/challenge-207/jaldhar-h-vyas/raku/ch-1.raku new file mode 100755 index 0000000000..dcddd573b6 --- /dev/null +++ b/challenge-207/jaldhar-h-vyas/raku/ch-1.raku @@ -0,0 +1,20 @@ +#!/usr/bin/raku + +sub MAIN( + *@words +) { + my @rows = < qwertyuiop asdfghjkl zxcvbnm >.map({ $_.comb; }); + my @output; + + for @words -> $word { + my @letters = $word.lc.comb; + for @rows -> $row { + if @letters ⊆ @$row { + @output.push($word); + last; + } + } + } + + say q{(}, @output.map({ q{"} ~ $_ ~ q{"} }).join(q{,}), q{)}; +} diff --git a/challenge-207/jaldhar-h-vyas/raku/ch-2.raku b/challenge-207/jaldhar-h-vyas/raku/ch-2.raku new file mode 100755 index 0000000000..9fc233e547 --- /dev/null +++ b/challenge-207/jaldhar-h-vyas/raku/ch-2.raku @@ -0,0 +1,16 @@ +#!/usr/bin/raku + +sub MAIN( + *@citations +) { + my $hindex = 0; + + for 1 .. @citations.elems -> $h { + if @citations[$h - 1] < $h { + last; + } + $hindex = $h; + } + + say $hindex; +} |
