aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolathian <horvath6@gmail.com>2023-03-07 19:19:35 +0100
committerSolathian <horvath6@gmail.com>2023-03-07 19:19:35 +0100
commit97dad4d8cbd949bf7db3e0f726f1b730f7ba2735 (patch)
tree2e749164bab9c86558e5461ee025e5cc846557cd
parentd75c83429332efc88f29eee14f988b199f2fa10c (diff)
downloadperlweeklychallenge-club-97dad4d8cbd949bf7db3e0f726f1b730f7ba2735.tar.gz
perlweeklychallenge-club-97dad4d8cbd949bf7db3e0f726f1b730f7ba2735.tar.bz2
perlweeklychallenge-club-97dad4d8cbd949bf7db3e0f726f1b730f7ba2735.zip
Adding files for challenge
-rw-r--r--challenge-207/solathian/perl/ch-1.pl36
-rw-r--r--challenge-207/solathian/perl/ch-2.pl38
2 files changed, 74 insertions, 0 deletions
diff --git a/challenge-207/solathian/perl/ch-1.pl b/challenge-207/solathian/perl/ch-1.pl
new file mode 100644
index 0000000000..2ad2c3cad1
--- /dev/null
+++ b/challenge-207/solathian/perl/ch-1.pl
@@ -0,0 +1,36 @@
+#!usr/bin/perl
+use v5.36;
+
+# Challenge 207 - 1 -Keyboard Word
+# You are given an array of words.
+# Write a script to print all the words in the given array that can be types using alphabet
+# on only one row of the keyboard.
+
+# Let us assume the keys are arranged as below:
+# Row 1: qwertyuiop
+# Row 2: asdfghjkl
+# Row 3: zxcvbnm
+
+my @target = qw(qwertyuiop asdfghjkl zxcvbnm);
+
+keyboardWord("Hello","Alaska","Dad","Peace");
+keyboardWord("OMG","Bye");
+
+sub keyboardWord(@strings)
+{
+ my @result;
+
+ OUTER:foreach my $string (@strings)
+ {
+ INNER: foreach my $row (@target)
+ {
+ map{ next INNER if ( index($row, $_) == -1)} split('', lc($string));
+
+ push(@result, $string);
+ next OUTER;
+ }
+
+ }
+
+ say('(', join(', ',@result), ')');
+} \ No newline at end of file
diff --git a/challenge-207/solathian/perl/ch-2.pl b/challenge-207/solathian/perl/ch-2.pl
new file mode 100644
index 0000000000..696e384bb5
--- /dev/null
+++ b/challenge-207/solathian/perl/ch-2.pl
@@ -0,0 +1,38 @@
+#!usr/bin/perl
+use v5.36;
+
+# Challenge 207 - 2 - H index
+
+# The H-Index is the largest number h such that h articles have at least h citations each.
+# For example, if an author has five publications, with 9, 7, 6, 2, and 1 citations (ordered from greatest to least), then the author’s h-index is 3, because the author has three publications with 3 or more citations.
+# However, the author does not have four publications with 4 or more citations.
+
+
+hIndex(9, 7, 6, 2); # 3
+hIndex(10, 8, 5, 4, 3); # 4
+hIndex(25, 8, 5, 3, 3); # 3
+hIndex(1, 1, 1, 1, 1); # 1
+hIndex(2, 2); # 2
+
+sub count($threshold, $arrRef)
+{
+ my $count = 0;
+
+ map{$count++ if($_ >= $threshold)} @$arrRef;
+
+ return $count;
+}
+
+sub hIndex(@publications)
+{
+ my $h = $publications[0]+1; # consider it already sorted
+
+ do
+ {
+ $h--
+ }
+ while( $h > count($h, \@publications));
+
+
+ say $h;
+} \ No newline at end of file