diff options
| author | Jaldhar H. Vyas <jaldhar@braincells.com> | 2023-03-12 14:12:06 -0400 |
|---|---|---|
| committer | Jaldhar H. Vyas <jaldhar@braincells.com> | 2023-03-12 14:12:06 -0400 |
| commit | 8ba1aa77fa03cfad86609f6e0a358969e2c45c0a (patch) | |
| tree | f23751ce958bc0f6c4d0a42b42678114287fc271 | |
| parent | 1f9e919800ebc28992c10467f2e9a2d1afe90169 (diff) | |
| download | perlweeklychallenge-club-8ba1aa77fa03cfad86609f6e0a358969e2c45c0a.tar.gz perlweeklychallenge-club-8ba1aa77fa03cfad86609f6e0a358969e2c45c0a.tar.bz2 perlweeklychallenge-club-8ba1aa77fa03cfad86609f6e0a358969e2c45c0a.zip | |
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; +} |
