aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Green <mail@simon.green>2023-03-12 20:22:33 +1100
committerSimon Green <mail@simon.green>2023-03-12 20:22:33 +1100
commit2cd3b800e44ec0e1ec236c9f637cb692c794ebff (patch)
tree5867a4a05c6cf7842ae88270ec1887ceb7182996
parentd75c83429332efc88f29eee14f988b199f2fa10c (diff)
downloadperlweeklychallenge-club-2cd3b800e44ec0e1ec236c9f637cb692c794ebff.tar.gz
perlweeklychallenge-club-2cd3b800e44ec0e1ec236c9f637cb692c794ebff.tar.bz2
perlweeklychallenge-club-2cd3b800e44ec0e1ec236c9f637cb692c794ebff.zip
Simon's solution to challenge 207
-rw-r--r--challenge-207/sgreen/README.md4
-rw-r--r--challenge-207/sgreen/blog.txt1
-rwxr-xr-xchallenge-207/sgreen/perl/ch-1.pl17
-rwxr-xr-xchallenge-207/sgreen/perl/ch-2.pl28
-rwxr-xr-xchallenge-207/sgreen/python/ch-1.py17
-rwxr-xr-xchallenge-207/sgreen/python/ch-2.py24
6 files changed, 89 insertions, 2 deletions
diff --git a/challenge-207/sgreen/README.md b/challenge-207/sgreen/README.md
index 36f49d2ad5..9a014752a8 100644
--- a/challenge-207/sgreen/README.md
+++ b/challenge-207/sgreen/README.md
@@ -1,3 +1,3 @@
-# The Weekly Challenge 206
+# The Weekly Challenge 207
-Blog: [Weekly Challenge 206](https://dev.to/simongreennet/weekly-challenge-206-2god)
+Blog: [The H Word](https://dev.to/simongreennet/the-h-word-3neh)
diff --git a/challenge-207/sgreen/blog.txt b/challenge-207/sgreen/blog.txt
new file mode 100644
index 0000000000..54b1293b8b
--- /dev/null
+++ b/challenge-207/sgreen/blog.txt
@@ -0,0 +1 @@
+https://dev.to/simongreennet/the-h-word-3neh \ No newline at end of file
diff --git a/challenge-207/sgreen/perl/ch-1.pl b/challenge-207/sgreen/perl/ch-1.pl
new file mode 100755
index 0000000000..746a7c6a8d
--- /dev/null
+++ b/challenge-207/sgreen/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+sub main (@words) {
+ # Define the regular expression that makes up a single line on a keyboard
+ my $r = '^(?:[qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$';
+
+ # Find all words that match the pattern, and print it
+ my @matched_words = grep { m{$r}i } @words;
+ say '(', join( ',', map { qq{"$_"} } @matched_words ), ')';
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-207/sgreen/perl/ch-2.pl b/challenge-207/sgreen/perl/ch-2.pl
new file mode 100755
index 0000000000..1b03905b85
--- /dev/null
+++ b/challenge-207/sgreen/perl/ch-2.pl
@@ -0,0 +1,28 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use feature 'say';
+use experimental 'signatures';
+
+use List::Util qw(pairkeys sum);
+
+sub main (@n) {
+ my $h_index = 0;
+
+ foreach my $i ( 1 .. $#n + 1 ) {
+ # Count the number of items that are >= i
+ my $count = sum( map { $_ >= $i } @n );
+ if ( $count >= $i ) {
+ $h_index = $i;
+ }
+ else {
+ # No point trying any more, as it will be False.
+ last;
+ }
+ }
+
+ say $h_index;
+}
+
+main(@ARGV); \ No newline at end of file
diff --git a/challenge-207/sgreen/python/ch-1.py b/challenge-207/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..dd6a15c15a
--- /dev/null
+++ b/challenge-207/sgreen/python/ch-1.py
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+
+
+def main(words):
+ # Define the regular expression that makes up a single line on a keyboard
+ r = '^(?:[qwertyuiop]+|[asdfghjkl]+|[zxcvbnm]+)$'
+
+ # Find all words that match the pattern, and print it
+ matched_words = [w for w in words if re.search(r, w, re.IGNORECASE)]
+ print('(' + ','.join(f'"{w}"' for w in matched_words) + ')')
+
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/challenge-207/sgreen/python/ch-2.py b/challenge-207/sgreen/python/ch-2.py
new file mode 100755
index 0000000000..e76b64c03f
--- /dev/null
+++ b/challenge-207/sgreen/python/ch-2.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(n):
+ h_index = 0
+
+ for i in range(1, len(n)+1):
+ # Count the number of items that are >= i
+ count = sum(1 for x in n if x >= i)
+ if count >= i:
+ h_index = i
+ else:
+ # No point trying any more, as it will be False.
+ break
+
+ print(h_index)
+
+
+if __name__ == '__main__':
+ # Turn the strings into integers
+ n = [int(i) for i in sys.argv[1:]]
+ main(n)